Submission #1129148

#TimeUsernameProblemLanguageResultExecution timeMemory
1129148idkfrKnapsack (NOI18_knapsack)C++20
37 / 100
1 ms328 KiB
#include<bits/stdc++.h> using namespace std; int main() { int n, W; cin >> W >> n; vector<long long> dp(W + 1, 0); for (int i = 0; i < n; ++i) { int wi, vi, ai; cin >> vi >> wi >> ai; for (int k = 1; ai > 0; k *= 2) { int num = min(k, ai); ai -= num; int weight = num * wi; int value = num * vi; for (int j = W; j >= weight; --j) { dp[j] = max(dp[j], dp[j - weight] + value); } } } cout << dp[W] << endl; 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...