forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 0
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);
}
}