fork download
  1. #include <bits/stdc++.h>
  2. #define int long long
  3.  
  4. using namespace std;
  5.  
  6. int dp[111][100111];
  7. int W, n;
  8. int v[100111];
  9. int w[100111];
  10.  
  11. int32_t main() {
  12. ios_base::sync_with_stdio(false);
  13. cin.tie(NULL);
  14.  
  15. cin >> n >> W;
  16. for (int i = 1; i <= n; i += 1) {
  17. cin >> w[i] >> v[i];
  18. }
  19.  
  20. for (int i = 1; i <= n; i += 1) {
  21. for (int j = 0; j <= W; j += 1) {
  22. if (w[i] > j) {
  23. dp[i][j] = dp[i-1][j];
  24. } else {
  25. dp[i][j] = max(dp[i-1][j], v[i] + dp[i-1][j-w[i]]);
  26. }
  27. }
  28. }
  29.  
  30. cout << dp[n][W];
  31.  
  32. return 0;
  33. }
Success #stdin #stdout 0s 5260KB
stdin
Standard input is empty
stdout
Standard output is empty