fork(7) download
  1. #include <bits/stdc++.h>
  2.  
  3. const int64_t INF = 1e18;
  4.  
  5. signed main() {
  6. std::ios_base::sync_with_stdio(false); std::cin.tie(NULL);
  7.  
  8. int n, W;
  9. std::cin >> n >> W;
  10.  
  11. std::vector<int> w(n + 1);
  12. std::vector<int> v(n + 1);
  13.  
  14. for (int i = 1; i <= n; i++) {
  15. std::cin >> w[i] >> v[i];
  16. }
  17.  
  18. int MAX = *std::max_element(v.begin() + 1, v.end()) * n;
  19. std::vector<int64_t> dp(MAX + 1, INF);
  20. dp[0] = 0;
  21.  
  22. for (int i = 1; i <= n; i++) {
  23. for (int j = MAX; j >= v[i]; j--) {
  24. if (dp[j - v[i]] == INF) continue;
  25. dp[j] = std::min(dp[j], dp[j - v[i]] + w[i]);
  26. }
  27. }
  28.  
  29. for (int i = MAX; i >= 0; i--) {
  30. if (dp[i] <= W) {
  31. std::cout << i;
  32. break;
  33. }
  34. }
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 4220KB
stdin
3 8
3 30
4 50
5 60
stdout
90