Skip to content

Commit 4cd8109

Browse files
authored
[20260112] BOJ / G2 / 저울 / 한종욱
1 parent f5ac238 commit 4cd8109

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

Ukj0ng/202601/12 BOJ G2 저울.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static int[] weight;
9+
private static int N, sum, answer;
10+
11+
public static void main(String[] args) throws IOException {
12+
init();
13+
14+
bw.write(answer+"\n");
15+
bw.flush();
16+
bw.close();
17+
br.close();
18+
}
19+
20+
private static void init() throws IOException {
21+
N = Integer.parseInt(br.readLine());
22+
weight = new int[N];
23+
24+
StringTokenizer st = new StringTokenizer(br.readLine());
25+
for (int i = 0; i < N; i++) {
26+
weight[i] = Integer.parseInt(st.nextToken());
27+
}
28+
29+
Arrays.sort(weight);
30+
31+
sum = 0;
32+
33+
for (int i = 0; i < N; i++) {
34+
if (weight[i] > sum+1) {
35+
break;
36+
}
37+
sum += weight[i];
38+
}
39+
40+
answer = sum+1;
41+
}
42+
}
43+
```

0 commit comments

Comments
 (0)