Submission #1302500

#TimeUsernameProblemLanguageResultExecution timeMemory
1302500ramzialoulouKnapsack (NOI18_knapsack)C++20
73 / 100
1095 ms1608 KiB
#include <bits/stdc++.h> 

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int s, n;
  cin >> s >> n;
  vector<int> v(n), w(n), k(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i] >> w[i] >> k[i];
  }
  vector<int> dp(s + 1);
  for (int p = 0; p < n; p++) {
    vector<int> nw_dp = dp;
    for (int W = 0; W <= s; W++) {
      for (int K = 1; K <= k[p] && W + K * w[p] <= s; K++) {
        nw_dp[W + K * w[p]] = max(nw_dp[W + K * w[p]], dp[W] + K * v[p]);
      }
    }
    swap(dp, nw_dp);
  }
  cout << dp[s] << '\n';
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...