File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments