Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- typedef long long ll;
- const ll mx = 1e5+10;
- ll n,w;
- ll weight[mx];
- ll cost[mx];
- int solve(ll i,ll we)
- {
- ll profit,profit1;
- if(i==n+1)
- return 0;
- if(we+weight[i]<=w)
- {
- profit = cost[i]+solve(i+1,we+weight[i]);
- }
- else profit = 0;
- profit1 = solve(i+1,we);
- return max(profit,profit1);
- }
- int main()
- {
- cin>>n>>w;
- for(int i=0;i<n;i++)
- {
- cin>>weight[i]>>cost[i];
- }
- cout<<(ll)solve(0,0)<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement