Submission #1129126

#TimeUsernameProblemLanguageResultExecution timeMemory
1129126idkfrKnapsack (NOI18_knapsack)C++20
0 / 100
1 ms320 KiB
#include<bits/stdc++.h> using namespace std; int main() { int n, W; cin >> n >> W; vector<int> dp(W + 1, 0); for (int i = 0; i < n; ++i) { int wi, vi, ai; cin >> wi >> vi >> 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...