Submission #844771

#TimeUsernameProblemLanguageResultExecution timeMemory
844771qrnoKnapsack (NOI18_knapsack)C++17
73 / 100
1072 ms19404 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; for (int i = 0; i < N; i++) { int v, w, k; cin >> v >> w >> k; int cnt = 1; while (k) { 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...