Skip to content

Commit ff62d1d

Browse files
authored
Merge pull request #524 from AlgorithmWithGod/lkhyun
[20250722] BOJ / G5 / 두 개의 탑 / 이강현
2 parents ab85b0a + b547625 commit ff62d1d

File tree

1 file changed

+44
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)