File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ //https://www.acmicpc.net/problem/20162
2+ import java .io .BufferedReader ;
3+ import java .io .IOException ;
4+ import java .io .InputStreamReader ;
5+
6+ public class BOJ_S2_20162_간식파티 {
7+ public static void main (String [] args ) throws IOException {
8+ BufferedReader br = new BufferedReader (new InputStreamReader (System .in ));
9+
10+ int N = Integer .parseInt (br .readLine ());
11+ int [] arr = new int [N ];
12+ int [] dp = new int [N ];
13+
14+ for (int i = 0 ; i < N ; i ++) {
15+ int score = Integer .parseInt (br .readLine ());
16+ arr [i ] = score ;
17+ dp [i ] = score ;
18+ }
19+
20+ for (int i = 1 ; i < N ; i ++) {
21+ for (int j = 0 ; j < i ; j ++) {
22+ if (arr [j ] >= arr [i ]) continue ;
23+
24+ dp [i ] = Math .max (dp [i ], dp [j ]+arr [i ]);
25+ }
26+ }
27+
28+ int max = 0 ;
29+ for (int i = 0 ; i < N ; i ++) {
30+ max = Math .max (max , dp [i ]);
31+ }
32+
33+ System .out .println (max );
34+
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments