fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. using namespace std;
  4. const int N = 110;
  5. ll n, s;
  6. ll v[N], w[N];
  7. ll dp[N][100004];
  8. int main()
  9. {
  10. freopen("spestore.inp", "r", stdin);
  11. freopen("spestore.out", "w", stdout);
  12. cin >> n >> s;
  13. for (ll i=1; i<=n; i++)
  14. cin >> w[i] >> v[i];
  15. for (ll i=0; i<=n; i++)
  16. for (ll j=0; j<=s; j++)
  17. {
  18. dp[i][j] = -1e9;
  19. }
  20. dp[0][0] = 0;
  21. for (ll i=1; i<=n; i++)
  22. for (ll j=0; j<=s; j++)
  23. {
  24. if (j>=w[i])
  25. {
  26. for (ll k=0; k<i; k++)
  27. if (v[k]<v[i])
  28. {
  29. dp[i][j] = max(dp[i][j], dp[k][j-w[i]]+v[i]);
  30. }
  31. }
  32. }
  33. ll res = 0;
  34. for (ll i=1; i<=n; i++)
  35. {
  36. res = max(res, dp[i][s]);
  37. }
  38. cout << res;
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0.01s 5292KB
stdin
Standard input is empty
stdout
Standard output is empty