Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int n,g,i,Max,j,a[1002],b[1002],max1,s1[1000*10000+2],x;
  5. //ifstream cin("seful.in");
  6. //ofstream cout("seful.out");
  7. int main()
  8. {
  9. cin>>n>>g;
  10. for(i=1;i<=n;i++)
  11. {
  12. cin>>a[i]>>b[i];
  13. }
  14. for(i=1;i<=g;i++)
  15. {
  16. s1[i]=-1;
  17. }
  18. Max=0;
  19. for(i=1;i<=n;i++)
  20. {
  21. for(j=g-a[i];j>=0;j--)
  22. {
  23. if(s1[j]!=-1)
  24. {
  25. s1[j+a[i]]=max(s1[j+a[i]],s1[j]+b[i]);
  26. if(s1[j+a[i]]>max1)max1=s1[j+a[i]];
  27. }
  28. }
  29. }
  30. cout<<max1<<'\n';
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement