File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ ``` java
2+ import java.io.* ;
3+ import java.util.* ;
4+
5+ public class Main {
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 answer = Integer . MIN_VALUE ;
14+ int N = nextInt();
15+ int [] honey = new int [N + 1 ];
16+ int [][] sum = new int [2 ][N + 2 ];
17+ nextLine();
18+ for (int i = 1 ; i <= N ; i++ ) honey[i] = nextInt();
19+ for (int i = 1 ; i <= N ; i++ ) {
20+ sum[0 ][i] = sum[0 ][i- 1 ] + honey[i]; // 왼오
21+ sum[1 ][N - i+ 1 ] = sum[1 ][N - i+ 2 ] + honey[N - i+ 1 ]; // 오왼
22+ }
23+ // 벌통 오른쪽 끝
24+ for (int i = 2 ; i <= N - 1 ; i++ ){
25+ int cur = (sum[0 ][N ] - sum[0 ][1 ] - honey[i]) + (sum[0 ][N ] - sum[0 ][i]);
26+ answer = Math . max(answer, cur);
27+ }
28+ // 벌통 왼쪽 끝
29+ for (int i = N - 1 ; i >= 2 ; i-- ){
30+ int cur = (sum[1 ][1 ] - sum[1 ][N ] - honey[i]) + (sum[1 ][1 ] - sum[1 ][i]);
31+ answer = Math . max(answer, cur);
32+ }
33+ // 벌통 가운데
34+ for (int i = 2 ; i <= N - 1 ; i++ ){
35+ answer = Math . max(answer, (sum[0 ][i] - sum[0 ][1 ]) + (sum[1 ][i] - sum[1 ][N ]));
36+ }
37+ System . out. println(answer);
38+ }
39+ }
40+ ```
You can’t perform that action at this time.
0 commit comments