fork download
  1. // author : anphung >> npkly
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. #define int64 long long
  5. #define f0(i,a,b) for(int (i)=(a);(i)<=(b);++i)
  6.  
  7. int n;int64 s;
  8. vector<int64>w;
  9. vector<int64>v;
  10. int64 ans;
  11. void Try(int i,int64 cw,int64 cv){
  12. if(i==n){
  13. if(cw<=s)ans = max(ans,cv);
  14. return;
  15. }
  16. Try(i+1,cw,cv);
  17. if(cw+w[i]<=s){
  18. Try(i+1,cw+w[i],cv+v[i]);
  19. }
  20. }
  21.  
  22. int32_t main(){
  23. ios::sync_with_stdio(0);cin.tie(0);
  24. cin>>n>>s;
  25. v.resize(n);w.resize(n);
  26. f0(i,0,n-1){
  27. cin>>w[i]>>v[i];
  28. }
  29. ans=0;
  30. Try(0,0,0);
  31. cout<<ans;
  32. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Standard output is empty