Advertisement
hkshakib

Untitled

Mar 30th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll mx = 1e5+10;
  5. ll n,w;
  6. ll weight[mx];
  7. ll cost[mx];
  8. int solve(ll i,ll we)
  9. {
  10. ll profit,profit1;
  11. if(i==n+1)
  12. return 0;
  13. if(we+weight[i]<=w)
  14. {
  15. profit = cost[i]+solve(i+1,we+weight[i]);
  16. }
  17. else profit = 0;
  18.  
  19. profit1 = solve(i+1,we);
  20. return max(profit,profit1);
  21. }
  22. int main()
  23. {
  24. cin>>n>>w;
  25. for(int i=0;i<n;i++)
  26. {
  27. cin>>weight[i]>>cost[i];
  28. }
  29. cout<<(ll)solve(0,0)<<endl;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement