Skip to content

Commit 0e99db4

Browse files
authored
Merge pull request #636 from AlgorithmWithGod/0224LJH
[20250809] BOJ / G2 / 저울 / 이종환
2 parents d502748 + f0fa933 commit 0e99db4

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

0224LJH/202508/9 BOJ 저울.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```java
2+
import java.awt.*;
3+
import java.io.BufferedReader;
4+
import java.io.IOException;
5+
import java.io.InputStreamReader;
6+
import java.util.*;
7+
import java.util.List;
8+
9+
10+
public class Main {
11+
12+
static int size,ans;
13+
static int[] arr;
14+
15+
16+
17+
public static void main(String[] args) throws IOException {
18+
init();
19+
process();
20+
print();
21+
}
22+
23+
private static void init() throws IOException {
24+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
25+
size = Integer.parseInt(br.readLine());
26+
arr = new int[size];
27+
ans = 0;
28+
StringTokenizer st = new StringTokenizer(br.readLine());
29+
30+
for (int i = 0; i < size; i++) {
31+
arr[i] = Integer.parseInt(st.nextToken());
32+
}
33+
34+
35+
}
36+
37+
private static void process() throws IOException {
38+
Arrays.sort(arr);
39+
40+
if ( arr[0] != 1) return;
41+
ans = 1;
42+
43+
for (int i = 1; i < arr.length; i++) {
44+
if (arr[i] > ans +1) {
45+
return;
46+
}
47+
ans += arr[i];
48+
49+
}
50+
51+
52+
53+
}
54+
55+
56+
private static void print() {
57+
System.out.println(ans+1);
58+
}
59+
}
60+
```

0 commit comments

Comments
 (0)