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