Advertisement
a53

Tinder

a53
Jan 26th, 2021
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. #include <iostream>
  2. #define N 5005
  3. using namespace std;
  4. int n,gmax,i,j,v[N],g[N],t,h;
  5. long long a[2][N*2];
  6.  
  7. int main()
  8. {
  9. ios_base::sync_with_stdio(false);
  10. cin.tie(NULL); cout.tie(NULL);
  11. cin>>n>>gmax ;
  12. for(i=1;i<=n;++i)
  13. cin>>v[i]>>g[i];
  14. for(i=1;i<=n;++i)
  15. {
  16. if(i%2==0)
  17. t=1,h=0;
  18. else
  19. t=0,h=1;
  20. for(j=1;j<=gmax;++j)
  21. if(j>=g[i])
  22. a[h][j]=max(a[t][j],a[t][j-g[i]]+v[i]);
  23. else
  24. a[h][j]=a[t][j];
  25. }
  26. cout<<a[n%2][gmax];
  27. return 0;
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement