File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed
Expand file tree Collapse file tree 1 file changed +41
-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 boj2118 {
6+ static BufferedReader br = new BufferedReader (new InputStreamReader (System . in));
7+ static StringTokenizer st;
8+ static void nextLine () throws Exception {st = new StringTokenizer (br .readLine ());}
9+ static int nextInt() {return Integer . parseInt(st. nextToken());}
10+
11+ public static void main(String [] args) throws Exception {
12+ nextLine();
13+ int N = nextInt();
14+ int sum = 0 ;
15+ int [] dist = new int [N + 1 ];
16+
17+ for (int i= 0 ;i< N ;i++ ){
18+ nextLine();
19+ dist[i] = nextInt();
20+ sum += dist[i];
21+ }
22+
23+ int start = 0 , last = 0 , result = 0 ;
24+ int now = dist[start];
25+
26+ while (start <= last && last < N ){
27+ int minNow = Integer . min(now,sum - now);
28+ result = Integer . max(result, minNow);
29+ if (now == minNow){
30+ last++ ;
31+ now += dist[last];
32+ }
33+ else {
34+ now -= dist[start];
35+ start++ ;
36+ }
37+ }
38+ System . out. println(result);
39+ }
40+ }
41+ ```
You can’t perform that action at this time.
0 commit comments