File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed
Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments