Submission #750351

#TimeUsernameProblemLanguageResultExecution timeMemory
750351nguyenneheheKnapsack (NOI18_knapsack)C++14
73 / 100
1079 ms17720 KiB
#include<bits/stdc++.h> using namespace std; signed main() { cin.tie(nullptr)->sync_with_stdio(false); int s, n; cin >> s >> n; vector<pair<long long, long long>> a; for (int i = 1; i <= n; ++i) { int v, w, k; cin >> v >> w >> k; long long pw = 1; while (pw <= k) { k -= pw; a.emplace_back(w * pw, v * pw); pw <<= 1; } if (k > 0) a.emplace_back(1LL * w * k, 1LL * v * k); } vector<long long> dp(s + 1); for (auto p: a) { for (int w = s; w >= p.first; --w) { dp[w] = max(dp[w], dp[w - p.first] + p.second); } } cout << *max_element(dp.begin(), dp.end()); }
#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...