File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Expand file tree Collapse file tree 1 file changed +36
-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+
6+
7+ public class B13398 {
8+
9+ private static BufferedReader br;
10+ private static int n;
11+ private static int [] arr;
12+ private static int [][] dp;
13+
14+ public static void main (String [] args ) throws IOException {
15+ br = new BufferedReader (new InputStreamReader (System . in));
16+ n = Integer . parseInt(br. readLine());
17+ arr = new int [n];Q
18+ String [] temp = br. readLine(). split(" " );
19+ for (int i = 0 ; i< n; i++ )
20+ arr[i] = Integer . parseInt(temp[i]);
21+
22+ // dp 설정
23+ dp = new int [n+ 1 ][2 ];
24+ int answer = - 1000 ;
25+ answer = dp[0 ][0 ] = dp[0 ][1 ] = arr[0 ];
26+ for (int i = 1 ; i< n; i++ ) {
27+ dp[i][0 ] = Math . max(dp[i- 1 ][0 ] + arr[i], arr[i]);
28+ dp[i][1 ] = Math . max(dp[i- 1 ][0 ],dp[i- 1 ][1 ] + arr[i]);
29+ answer = Math . max(answer, Math . max(dp[i][0 ], dp[i][1 ]));
30+ }
31+
32+ System . out. println(answer);
33+ }
34+
35+ }
36+ ```
You can’t perform that action at this time.
0 commit comments