-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbaekjoon_12865.java
More file actions
44 lines (31 loc) · 1.1 KB
/
baekjoon_12865.java
File metadata and controls
44 lines (31 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.*;
import java.io.*;
public class baekjoon_12865 {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
int N, K;
N = Integer.parseInt(st.nextToken());
K = Integer.parseInt(st.nextToken());
int[][] stuff = new int[N+1][2];
int[][] dp = new int[N+1][K+1];
for(int i=1;i<=N;i++) {
st = new StringTokenizer(br.readLine());
stuff[i][0] = Integer.parseInt(st.nextToken());
stuff[i][1] = Integer.parseInt(st.nextToken());
}
for(int i=1;i<=N;i++) {
int W = stuff[i][0];
int V = stuff[i][1];
for(int j=0;j<=K;j++){
if( j < W) {
dp[i][j] = dp[i-1][j];
}
else {
dp[i][j] = Math.max(dp[i-1][j], dp[i - 1][j - W] + V);
}
}
}
System.out.println(dp[N][K]);
}
}