fork download
  1. #include <bits/stdc++.h>
  2. long long n,w,p[10000000],v[10000000],d[10000000],tong=0,tl=0,t=0;
  3. using namespace std;
  4. void Try(long long i)
  5. {
  6. for (long long j=1;j<=n;j++)
  7. {
  8. if (d[j]==0)
  9. if (tl+p[j]>w)
  10. {
  11. break;
  12. }
  13. else
  14. {
  15. d[j]=1;
  16. tl+=p[j];
  17. t+=v[j];
  18. tong=max(tong,t);
  19. Try(i+1);
  20. d[j]=0;
  21. tl-=p[j];
  22. t-=v[j];
  23. }
  24. }
  25. }
  26. int main() {
  27. freopen("balo.inp","r",stdin);
  28. freopen("balo.out","w",stdout);
  29. cin>>n>>w;
  30. for (long long i=1;i<=n;++i)
  31. cin>>p[i]>>v[i];
  32. Try(1);
  33. cout<<tong;
  34. return 0;}
  35.  
Success #stdin #stdout 0s 5268KB
stdin
Standard input is empty
stdout
Standard output is empty