forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1.cpp
More file actions
31 lines (23 loc) ยท 863 Bytes
/
1.cpp
File metadata and controls
31 lines (23 loc) ยท 863 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> arr;
int main(void) {
cin >> n;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
arr.push_back(x);
}
sort(arr.begin(), arr.end());
int result = 0; // ์ด ๊ทธ๋ฃน์ ์
int count = 0; // ํ์ฌ ๊ทธ๋ฃน์ ํฌํจ๋ ๋ชจํ๊ฐ์ ์
for (int i = 0; i < n; i++) { // ๊ณตํฌ๋๋ฅผ ๋ฎ์ ๊ฒ๋ถํฐ ํ๋์ฉ ํ์ธํ๋ฉฐ
count += 1; // ํ์ฌ ๊ทธ๋ฃน์ ํด๋น ๋ชจํ๊ฐ๋ฅผ ํฌํจ์ํค๊ธฐ
if (count >= arr[i]) { // ํ์ฌ ๊ทธ๋ฃน์ ํฌํจ๋ ๋ชจํ๊ฐ์ ์๊ฐ ํ์ฌ์ ๊ณตํฌ๋ ์ด์์ด๋ผ๋ฉด, ๊ทธ๋ฃน ๊ฒฐ์ฑ
result += 1; // ์ด ๊ทธ๋ฃน์ ์ ์ฆ๊ฐ์ํค๊ธฐ
count = 0; // ํ์ฌ ๊ทธ๋ฃน์ ํฌํจ๋ ๋ชจํ๊ฐ์ ์ ์ด๊ธฐํ
}
}
cout << result << '\n'; // ์ด ๊ทธ๋ฃน์ ์ ์ถ๋ ฅ
}