Skip to content

Commit 292a328

Browse files
authored
Merge pull request #1730 from AlgorithmWithGod/zinnnn37
[20251223] BOJ / G5 / 두 개의 탑 / 김민진
2 parents 6a42c4e + ba5f561 commit 292a328

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
```java
2+
import java.io.*;
3+
4+
public class BJ_2118_두_개의_탑 {
5+
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+
9+
private static int N, ans, half;
10+
private static int[] dist;
11+
12+
public static void main(String[] args) throws IOException {
13+
init();
14+
sol();
15+
}
16+
17+
private static void init() throws IOException {
18+
N = Integer.parseInt(br.readLine());
19+
ans = 0;
20+
dist = new int[2 * N];
21+
22+
for (int i = 0; i < N; i++) {
23+
dist[i] = Integer.parseInt(br.readLine());
24+
dist[i + N] = dist[i];
25+
half += dist[i];
26+
}
27+
half /= 2;
28+
}
29+
30+
private static void sol() throws IOException {
31+
int left = 0;
32+
int right = 0;
33+
int curDist = 0;
34+
35+
while (left < N) {
36+
while (true) {
37+
curDist += dist[right++];
38+
if (curDist > half) {
39+
curDist -= dist[--right];
40+
break;
41+
}
42+
}
43+
44+
ans = Math.max(ans, curDist);
45+
curDist -= dist[left++];
46+
}
47+
bw.write(ans + "");
48+
bw.flush();
49+
bw.close();
50+
br.close();
51+
}
52+
53+
}
54+
```

0 commit comments

Comments
 (0)