Submission #1218182

#TimeUsernameProblemLanguageResultExecution timeMemory
1218182shuvo_06Knapsack (NOI18_knapsack)C++20
73 / 100
1096 ms464 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int S, N; cin >> S >> N; vector<int> dp(S + 1, 0); for (int i = 0; i < N; i++) { int val, wt, cnt; cin >> val >> wt >> cnt; if (wt > S) continue; for (int r = 0; r < wt; r++) { deque<pair<int,int>> dq; for (int j = 0, pos = r; pos <= S; j++, pos += wt) { int cur = dp[pos] - j * val; while (!dq.empty() && dq.back().first <= cur) dq.pop_back(); dq.emplace_back(cur, j); while (dq.front().second < j - cnt) dq.pop_front(); dp[pos] = dq.front().first + j * val; } } } cout << *max_element(dp.begin(), dp.end()) << "\n"; 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...