File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed
Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .io .*;
2+ import java .util .*;
3+
4+ class Main {
5+ public static void main (String [] args ) throws Exception {
6+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
7+ BufferedWriter bw = new BufferedWriter (new OutputStreamWriter (System .out ));
8+ int n = Integer .parseInt (br .readLine ());
9+ StringTokenizer st = new StringTokenizer (br .readLine ());
10+ long [] me = new long [n / 2 ];
11+ long [] other = new long [n / 2 ];
12+
13+ for (int i = 0 ; i < n ; i ++) {
14+ int number = Integer .parseInt (st .nextToken ());
15+ if (i % 2 == 0 ) {
16+ me [i / 2 ] = number ;
17+ if (i / 2 > 0 ) {
18+ me [i / 2 ] += me [i / 2 - 1 ];
19+ }
20+ } else {
21+ other [i / 2 ] = number ;
22+ if (i / 2 > 0 ) {
23+ other [i / 2 ] += other [i / 2 - 1 ];
24+ }
25+ }
26+ }
27+ if (n == 2 ) {
28+ bw .write (Long .toString (Math .max (me [0 ], other [0 ])));
29+ bw .flush ();
30+ bw .close ();
31+ return ;
32+ }
33+
34+ long max = Math .max (me [n / 2 - 1 ], other [n / 2 - 1 ]); // 밑장 안뻈을때 vs 내걸 첫번째 밑장 빼기
35+ max = Math .max (me [0 ] + other [n / 2 - 2 ], max );
36+
37+ for (int i = 1 ; i < n / 2 ; i ++) {
38+ max = Math .max (max , me [i - 1 ] + other [n / 2 - 1 ] - other [i - 1 ]); // 내걸 밑장빼기
39+ max = Math .max (max , me [i ] + other [n / 2 - 2 ] - other [i - 1 ]); // 상대방을 밑장빼기
40+ }
41+
42+ bw .write (Long .toString (max ));
43+ bw .flush ();
44+ bw .close ();
45+ }
46+ }
You can’t perform that action at this time.
0 commit comments