Submission #1305926

#TimeUsernameProblemLanguageResultExecution timeMemory
1305926avsKnapsack (NOI18_knapsack)C++20
37 / 100
2 ms584 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> x >> n; vector<int> w(n), v(n), k(n), dp(x+1); for (int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i]; for (int i = 0; i < n; i++) { int count = k[i]; for (int mul = 1; count > 0; mul <<= 1) { int take = min(mul,count); int tw = take * w[i]; int tv = take * v[i]; for (int j = x; j >= tw; j--) dp[j] = max(dp[j],dp[j-tw]+tv); count -= take; } } cout << dp.back(); }
#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...