-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_2118.java
More file actions
33 lines (28 loc) · 1013 Bytes
/
Copy pathBOJ_2118.java
File metadata and controls
33 lines (28 loc) · 1013 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// BOJ - 2118
// Problem Sheet - https://www.acmicpc.net/problem/2118
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] acc = new int[N + 1];
for (int i=1 ; i<=N ; i++) {
acc[i] = acc[i - 1] + Integer.parseInt(br.readLine());
}
int left = 0, right = 1;
int maxDist = 0;
while (left <= right && right <= N) {
int clockwiseDist = acc[right] - acc[left];
int counterClockwiseDist = acc[N] - clockwiseDist;
int dist = Math.min(clockwiseDist, counterClockwiseDist);
maxDist = Math.max(dist, maxDist);
if (clockwiseDist <= counterClockwiseDist) {
right++;
} else {
left++;
}
}
System.out.println(maxDist);
br.close();
}
}