Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include<ctime>
- #include<map>
- #include<vector>
- #include<queue>
- using namespace std;
- typedef long long ll;
- ll dp[105][100005];
- int main()
- {
- int n, W;
- cin >> n >> W;
- vector<int> weight(n), value(n);
- int sum = 0;
- for(int i = 0; i < n; i++) {
- cin >> weight[i] >> value[i];
- sum += value[i];
- }
- for(int i = 0; i <= n; i++) {
- for(int j = 0; j <= sum; j++) {
- dp[i][j] = 1e18;
- }
- }
- dp[0][0] = 0;
- for(int i = 0; i < n; i++) {
- for(int j = 0; j <= sum; j++) {
- dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
- if(j + value[i] <= sum) {
- dp[i + 1][j + value[i]] = min(dp[i + 1][j + value[i]], dp[i][j] + weight[i]);
- }
- }
- }
- for(int i = sum; i >= 0; i--) {
- if(dp[n][i] <= W) {
- cout << i << endl;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement