Skip to content

Commit ae3ef40

Browse files
authored
Merge pull request #514 from AlgorithmWithGod/suyeun84
[20250721] BOJ / G5 / 벼락치기 / 김수연
2 parents dd47a95 + aecd775 commit ae3ef40

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class boj29704 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
static int n;
12+
static int t;
13+
static int[] dp;
14+
15+
public static void main(String[] args) throws Exception {
16+
nextLine();
17+
n = nextInt();
18+
t = nextInt();
19+
dp = new int[t+1];
20+
21+
int all = 0;
22+
while (n-- > 0) {
23+
nextLine();
24+
int d = nextInt();
25+
int m = nextInt();
26+
all += m;
27+
28+
for (int i = t; i >= 0; i--) {
29+
if (i < d) break;
30+
dp[i] = Math.max(dp[i], dp[i-d] +m);
31+
}
32+
}
33+
34+
System.out.println(all - dp[t]);
35+
}
36+
}
37+
```

0 commit comments

Comments
 (0)