Skip to content

Commit abe86a4

Browse files
authored
Merge pull request #1972 from AlgorithmWithGod/LiiNi-coder
[20260226] BOJ / G5 / 두개의 탑 / 이인희
2 parents eb74401 + 55dc55d commit abe86a4

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
```java
2+
import java.io.BufferedReader;
3+
import java.io.IOException;
4+
import java.io.InputStreamReader;
5+
6+
public class Main {
7+
static long[] Prefix;
8+
static long Total;
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
int N = Integer.parseInt(br.readLine().trim());
13+
long[] dist = new long[N];
14+
for(int i = 0; i < N; i++) {
15+
dist[i] = Long.parseLong(br.readLine());
16+
}
17+
18+
//원형 -> 배열을 2배
19+
Prefix = new long[2*N + 1];
20+
for(int i = 0; i < 2 * N; i++) {
21+
Prefix[i + 1] = Prefix[i] + dist[i % N];
22+
}
23+
Total = Prefix[N];
24+
long answer = 0;
25+
for(int i = 0; i < N; i++) {
26+
int l = i;
27+
int r = i + N;
28+
while(l + 1 < r) {
29+
int mid = (l+r) / 2;
30+
if(check(i, mid) == check(i, l)) {
31+
l = mid;
32+
}else {
33+
r = mid;
34+
}
35+
}
36+
long clockwise = Prefix[l] - Prefix[i];
37+
answer = Math.max(answer, clockwise);
38+
}
39+
40+
System.out.println(answer);
41+
}
42+
43+
static boolean check(int i, int mid) {
44+
return (Prefix[mid] - Prefix[i]<= Total/2);
45+
}
46+
}
47+
48+
```

0 commit comments

Comments
 (0)