File tree Expand file tree Collapse file tree 1 file changed +62
-0
lines changed
Expand file tree Collapse file tree 1 file changed +62
-0
lines changed 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+ import java.util.* ;
6+
7+ public class Main {
8+
9+ static int nodeCnt, sum,ans;
10+ static int [] arr;
11+
12+ public static void main (String [] args ) throws NumberFormatException , IOException {
13+ init();
14+ process();
15+ print();
16+
17+
18+ }
19+
20+ public static void init () throws NumberFormatException , IOException {
21+ BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
22+ nodeCnt = Integer . parseInt(br. readLine());
23+ arr = new int [nodeCnt];
24+ ans = 0 ;
25+ for (int i = 0 ; i < nodeCnt; i++ ) {
26+ arr[i] = Integer . parseInt(br. readLine());
27+ sum += arr[i];
28+ }
29+
30+ }
31+
32+ public static void process () {
33+ int halfSum = sum/ 2 ;
34+ int st = 0 ;
35+ int end = 0 ;
36+
37+ int curSum = arr[0 ];
38+
39+
40+ while (true ) {
41+ ans = Math . max(ans, Math . min(curSum, sum - curSum));
42+ if (curSum <= halfSum) {
43+ end++ ;
44+
45+ if (end >= nodeCnt) break ;
46+ curSum += arr[end];
47+ } else {
48+ curSum -= arr[st];
49+ st++ ;
50+ }
51+
52+ }
53+
54+ }
55+
56+
57+
58+ public static void print () {
59+ System . out. println(ans);
60+ }
61+ }
62+ ```
You can’t perform that action at this time.
0 commit comments