-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathac_dp_d.cpp
More file actions
52 lines (39 loc) · 1.03 KB
/
Copy pathac_dp_d.cpp
File metadata and controls
52 lines (39 loc) · 1.03 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
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
void solve();
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
void solve() {
int N, W;
cin >> N >> W;
vector<pair<int,int>> a(N);
for (int i = 0; i < N; ++i) {
cin >> a[i].first;
cin >> a[i].second;
}
vector<vector<long long>> dp(N, vector<long long>(W + 1));
dp[0][a[0].first] = a[0].second;
for (int i = 1; i < N; ++i) {
auto [wi, vi] = a[i];
for (int w = 0; w <= W; ++w) {
dp[i][w] = dp[i-1][w];
if (w >= wi) {
dp[i][w] = max(dp[i][w], dp[i - 1][w - wi] + vi);
}
}
}
long long ans = 0;
for (int w = 0; w <= W; ++w) {
ans = max(ans, dp[N - 1][w]);
}
cout << ans << '\n';
}