Skip to content

Commit 21f2f10

Browse files
authored
[20250826] BOJ / G5 / 퇴사2 / 이종환
1 parent 283de10 commit 21f2f10

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

0224LJH/202508/26 BOJ 퇴사2

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
7+
static int cnt,ans;
8+
static int[] cost;
9+
static int[] money;
10+
static int[] dp;
11+
12+
public static void main(String[] args) throws Exception {
13+
init();
14+
process();
15+
print();
16+
17+
}
18+
19+
public static void init() throws IOException {
20+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
21+
cnt = Integer.parseInt(br.readLine());
22+
cost = new int[cnt+1];
23+
money = new int[cnt+1];
24+
dp = new int[cnt+51];
25+
ans = 0;
26+
for (int i = 1; i <= cnt; i++) {
27+
StringTokenizer st = new StringTokenizer(br.readLine());
28+
cost[i] = Integer.parseInt(st.nextToken());
29+
money[i] = Integer.parseInt(st.nextToken());
30+
}
31+
}
32+
33+
public static void process(){
34+
for (int i = 1; i <= cnt; i++) {
35+
dp[i] = Math.max(dp[i],dp[i-1]);
36+
if (i + cost[i]-1 > cnt) {
37+
continue;
38+
}
39+
40+
dp[i + cost[i]-1] = Math.max (dp[i+cost[i]-1] , dp[i-1] + money[i]);
41+
}
42+
43+
for (int i = 1; i<= cnt; i++) {
44+
System.out.println(dp[i]);
45+
ans = Math.max(ans, dp[i]);
46+
}
47+
}
48+
49+
public static void print(){
50+
System.out.println(ans);
51+
}
52+
53+
```
54+
}

0 commit comments

Comments
 (0)