fork download
  1. #include <bits/stdc++.h>
  2. #define T int t;cin>>t;while(t--)
  3. #define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
  4. #define ll long long
  5. #define endl '\n'
  6. using namespace std;
  7. const ll N = 1e6 + 6;
  8. ll n, q;
  9. pair<ll, ll> pr[103];
  10. ll dp[103][N];
  11.  
  12. ll napsake(ll i, ll k, ll sum) {
  13. if (k > q) return 0;
  14. if (i == n) return sum;
  15. if (dp[i][k] != (-1)) return dp[i][k];
  16. ll o1 = (-1);
  17. if (k + pr[i].first <= q) o1 = napsake(i + 1, k + pr[i].first, sum + pr[i].second);
  18. ll o2 = napsake(i + 1, k, sum);
  19. return dp[i][k] = max(o1, o2);
  20. }
  21.  
  22. void Abady() {
  23. memset(dp, -1, sizeof(dp));
  24. cin >> n >> q;
  25. for (int i = 0; i < n; i++) {
  26. int a, b;
  27. cin >> a >> b;
  28. pr[i] = {a, b};
  29. }
  30. cout << napsake(0, 0, 0);
  31. }
  32.  
  33. int main() {
  34. fast;
  35. Abady();
  36. }
  37.  
Success #stdin #stdout 0.11s 808188KB
stdin
Standard input is empty
stdout
Standard output is empty