Skip to content

Commit b6af477

Browse files
authored
[20251013] BOJ / G5 / 두 개의 탑 / 한종욱
1 parent 8e57d3d commit b6af477

File tree

1 file changed

+48
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)