File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed
Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+
4+ public class BJ_2118_ 두_개의_탑 {
5+
6+ private static final BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ private static final BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System . out));
8+
9+ private static int N , ans, half;
10+ private static int [] dist;
11+
12+ public static void main (String [] args ) throws IOException {
13+ init();
14+ sol();
15+ }
16+
17+ private static void init () throws IOException {
18+ N = Integer . parseInt(br. readLine());
19+ ans = 0 ;
20+ dist = new int [2 * N ];
21+
22+ for (int i = 0 ; i < N ; i++ ) {
23+ dist[i] = Integer . parseInt(br. readLine());
24+ dist[i + N ] = dist[i];
25+ half += dist[i];
26+ }
27+ half /= 2 ;
28+ }
29+
30+ private static void sol () throws IOException {
31+ int left = 0 ;
32+ int right = 0 ;
33+ int curDist = 0 ;
34+
35+ while (left < N ) {
36+ while (true ) {
37+ curDist += dist[right++ ];
38+ if (curDist > half) {
39+ curDist -= dist[-- right];
40+ break ;
41+ }
42+ }
43+
44+ ans = Math . max(ans, curDist);
45+ curDist -= dist[left++ ];
46+ }
47+ bw. write(ans + " " );
48+ bw. flush();
49+ bw. close();
50+ br. close();
51+ }
52+
53+ }
54+ ```
You can’t perform that action at this time.
0 commit comments