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