Skip to content

Commit 5101745

Browse files
authored
Merge pull request #868 from AlgorithmWithGod/Ukj0ng
[20250911] BOJ / G5 / 벼락치기 / 한종욱
2 parents 048cd61 + 4d379df commit 5101745

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
```
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
private static int[] dp;
9+
private static int n, t;
10+
11+
public static void main(String[] args) throws IOException {
12+
init();
13+
solve();
14+
15+
bw.write(dp[t] + "\n");
16+
bw.flush();
17+
bw.close();
18+
br.close();
19+
}
20+
21+
private static void init() throws IOException {
22+
StringTokenizer st = new StringTokenizer(br.readLine());
23+
n = Integer.parseInt(st.nextToken());
24+
t = Integer.parseInt(st.nextToken());
25+
dp = new int[t + 1];
26+
}
27+
28+
private static void solve() throws IOException {
29+
for (int i = 0; i < n; i++) {
30+
StringTokenizer st = new StringTokenizer(br.readLine());
31+
int k = Integer.parseInt(st.nextToken());
32+
int s = Integer.parseInt(st.nextToken());
33+
34+
for (int j = t; j >= k; j--) {
35+
dp[j] = Math.max(dp[j], dp[j - k] + s);
36+
}
37+
}
38+
}
39+
}
40+
```

0 commit comments

Comments
 (0)