Submission #1111714

#TimeUsernameProblemLanguageResultExecution timeMemory
1111714slyceloteKnapsack (NOI18_knapsack)C++17
100 / 100
51 ms3708 KiB
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { cin.tie(0); iostream::sync_with_stdio(false); int s, n; cin >> s >> n; vector<vector<pair<int, int>>> que(s+1); while (n--) { int v, w, k; cin >> v >> w >> k; k = min(k, s / w); que[w].push_back(pair(v, k)); } vector<int> best(s+1); for (int w = 1; w <= s; ++w) { auto& v = que[w]; sort(v.begin(), v.end(), greater<>{}); int rem = s/w; for (auto [v, k] : v) { if (!rem) { break; } for (; k && rem; k--, rem--) { for (int i = s-w; i >= 0; --i) { auto& r = best[i+w]; r = max(r, best[i] + v); } } } } cout << best[s] << 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...