We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 354e07d commit ac64855Copy full SHA for ac64855
atcoder/abc060/D/main.cpp
@@ -0,0 +1,45 @@
1
+#include <bits/stdc++.h>
2
+
3
+using namespace std;
4
+using ll = long long;
5
6
+int N, W;
7
+vector<int> wss, vss;
8
9
+int solve() {
10
+ map<int,int> dp;
11
+ dp[0] = 0;
12
13
+ for (int i = 0; i < N; ++i) {
14
+ auto ndp = dp;
15
+ for (auto e : dp) {
16
+ auto w = e.first, v = e.second;
17
+ int nw = w + wss[i];
18
+ int nv = v + vss[i];
19
+ if (nw > W) continue;
20
+ ndp[nw] = max(ndp[nw], nv);
21
+ }
22
+ dp = ndp;
23
24
25
+ int ans = 0;
26
27
+ ans = max(ans, e.second);
28
29
+ return ans;
30
+}
31
32
+int main() {
33
+ ios_base::sync_with_stdio(false);
34
+ cin.tie(0); cout.tie(0);
35
36
+ cin >> N >> W;
37
+ wss.assign(N, 0);
38
+ vss.assign(N, 0);
39
40
+ cin >> wss[i] >> vss[i];
41
42
+ cout << solve() << endl;
43
44
+ return 0;
45
0 commit comments