forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path4.java
More file actions
27 lines (20 loc) Β· 658 Bytes
/
4.java
File metadata and controls
27 lines (20 loc) Β· 658 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
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 target = 1;
for (int i = 0; i < n; i++) {
// λ§λ€ μ μλ κΈμ‘μ μ°Ύμμ λ λ°λ³΅ μ’
λ£
if (target < arrayList.get(i)) break;
target += arrayList.get(i);
}
System.out.println(target);
}
}