Skip to content

Commit 24849a8

Browse files
authored
[BOJ] S2 20162 간식 파티 (S2)
1 parent e90d47e commit 24849a8

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

정건우/7주차/260210.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

0 commit comments

Comments
 (0)