Submission #844772

#TimeUsernameProblemLanguageResultExecution timeMemory
844772qrnoKnapsack (NOI18_knapsack)C++17
73 / 100
1043 ms23600 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<pair<int, int>> A; A.reserve(2'000 * 11); for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; k = min(k, S); int cnt = 1; while (true) { if (cnt <= k) { A.push_back({v*cnt, w*cnt}); k -= cnt; cnt *= 2; } else { A.push_back({v*k, w*k}); break; } } } vector<int> most(S+1); for (auto [v, w] : A) { for (int s = S; s-w >= 0; s--) { most[s] = max(most[s], most[s-w] + v); } } cout << *max_element(begin(most), end(most)) << endl; }
#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...