/
BOJ_14728.java
30 lines (24 loc) · 912 Bytes
/
BOJ_14728.java
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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in), 1 << 16);
public static void main(String[] args) throws Exception {
new Main().solution();
}
private void solution() throws Exception {
StringTokenizer st = new StringTokenizer(br.readLine());
int n = Integer.parseInt(st.nextToken());
int t = Integer.parseInt(st.nextToken());
int[] dp = new int[t+1];
while (n-->0) {
st = new StringTokenizer(br.readLine());
int k = Integer.parseInt(st.nextToken());
int s = Integer.parseInt(st.nextToken());
for (int i = t; i >= k; i--) {
dp[i] = Math.max(dp[i], dp[i-k] + s);
}
}
System.out.println(dp[t]);
}
}