Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- //#include <bits/stdc++.h>
- using namespace std;
- long long dp[101][100001];
- int main()
- {
- ios_base::sync_with_stdio(true);
- int n,W;
- cin>>n>>W;
- int sum = 0;
- for(int i=0;i<=n;i++)
- {
- for(int j=0;j<=100000;j++)
- {
- dp[i][j]=1e18;
- }
- }
- int value[n], weight[n];
- for(int i=0;i<n;i++)
- {
- cin >> weight[i] >> value[i] ;
- sum += value[i];
- }
- dp[0][0]=0;
- for(int i=0;i<n;i++)
- {
- for(int val=0;val<=sum;val++)
- {
- dp[i+1][val]=min(dp[i+1][val],dp[i][val]);
- if(val+value[i]<=sum)
- {
- dp[i+1][val+value[i]]=min(dp[i+1][val+value[i]], dp[i][val]+weight[i]);
- }
- }
- }
- int ans=0;
- for(int i=0;i<=sum;i++)
- {
- if(dp[n][i] <= W) {
- ans = i;
- }
- }
- cout<<ans<<endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement