forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path1.java
More file actions
31 lines (23 loc) ยท 1.01 KB
/
1.java
File metadata and controls
31 lines (23 loc) ยท 1.01 KB
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
import java.util.*;
public class Main {
public static int n;
public static ArrayList<Integer> arrayList = new ArrayList<>();
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
for (int i = 0; i < n; i++) {
arrayList.add(sc.nextInt());
}
Collections.sort(arrayList);
int result = 0; // ์ด ๊ทธ๋ฃน์ ์
int count = 0; // ํ์ฌ ๊ทธ๋ฃน์ ํฌํจ๋ ๋ชจํ๊ฐ์ ์
for (int i = 0; i < n; i++) { // ๊ณตํฌ๋๋ฅผ ๋ฎ์ ๊ฒ๋ถํฐ ํ๋์ฉ ํ์ธํ๋ฉฐ
count += 1; // ํ์ฌ ๊ทธ๋ฃน์ ํด๋น ๋ชจํ๊ฐ๋ฅผ ํฌํจ์ํค๊ธฐ
if (count >= arrayList.get(i)) { // ํ์ฌ ๊ทธ๋ฃน์ ํฌํจ๋ ๋ชจํ๊ฐ์ ์๊ฐ ํ์ฌ์ ๊ณตํฌ๋ ์ด์์ด๋ผ๋ฉด, ๊ทธ๋ฃน ๊ฒฐ์ฑ
result += 1; // ์ด ๊ทธ๋ฃน์ ์ ์ฆ๊ฐ์ํค๊ธฐ
count = 0; // ํ์ฌ ๊ทธ๋ฃน์ ํฌํจ๋ ๋ชจํ๊ฐ์ ์ ์ด๊ธฐํ
}
}
System.out.println(result);
}
}