Submission #1271734

#TimeUsernameProblemLanguageResultExecution timeMemory
1271734pvb.tunglamKnapsack (NOI18_knapsack)C++20
37 / 100
1 ms328 KiB
#include <bits/stdc++.h> // Put me to the test. I will be the best. using namespace std; int dp[10001]; int main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); int n, m; cin >> m >> n; vector <int> W; vector <int> V; V.push_back(1000000000); W.push_back(1000000000); for (int i = 1; i <= n; i ++) { int w, v, a; cin >> v >> w >> a; int pow = 1; while (a >= pow) { W.push_back(w * pow); V.push_back(v * pow); a -= pow; pow *= 2; } if (a > 0) { W.push_back(w * a); V.push_back(v * a); } } n = V.size() - 1; for (int i = 1; i <= n ; i ++) { for (int j = m; j >= 0; j --) { if (j >= W[i]) { dp[j] = max(dp[j], dp[j - W[i]] + V[i]); } } } cout << dp[m]; }
#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...