제출 #1075438

#제출 시각아이디문제언어결과실행 시간메모리
1075438juicyKnapsack (NOI18_knapsack)C++17
100 / 100
48 ms1884 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int s, n; cin >> s >> n; vector<int> dp(s + 1); vector<vector<array<int, 2>>> cands(s); while (n--) { int v, w, k; cin >> v >> w >> k; cands[--w].push_back({v, k}); } vector<array<int, 2>> items; for (int w = 0; w < s; ++w) { sort(cands[w].begin(), cands[w].end()); int cnt = s / (w + 1); while (cands[w].size() && cnt) { auto [x, y] = cands[w].back(); cands[w].pop_back(); int k = min(y, cnt); while (k--) { --cnt; items.push_back({w + 1, x}); } } } for (auto [w, x] : items) { for (int j = s; j >= w; --j) { dp[j] = max(dp[j], dp[j - w] + x); } } cout << dp.back(); return 0; }
#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...