Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- long long n;
- long long w;
- vector<pair<long long,long long>>v;
- long long dp[100005][105];
- long long f(long long k, long long idx)
- {
- if(k==0)
- {
- return 0;
- }
- if(idx==n)
- {
- return 1e16;
- }
- if(dp[k][idx]!=-1)
- {
- return dp[k][idx];
- }
- long long rez=1e16;
- if(k >= v[idx].second)
- rez=min(rez, f(k-v[idx].second,idx+1)+v[idx].first);///w
- rez=min(rez, f(k,idx+1));
- return dp[k][idx]=rez;
- }
- int main()
- {
- cin>>n>>w;
- long long x,y;
- memset(dp,-1,sizeof dp);
- for(long long i=0;i<n;i++)
- {
- cin>>x>>y;
- v.push_back({x,y});
- }
- for(long long i=100000;i>=0;i--)
- {
- if(f(i,0)<=w)
- {
- cout<<i;
- break;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement