Submission #1258214

#TimeUsernameProblemLanguageResultExecution timeMemory
1258214alizhanKnapsack (NOI18_knapsack)C++20
37 / 100
5 ms328 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::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 v, w, k; cin >> v >> w >> k; vector<int> new_dp = dp; for (int r = 0; r < w; ++r) { deque<pair<int, int>> q; for (int j = r; j <= S; j += w) { while (!q.empty() && q.front().second < j - k * w) q.pop_front(); while (!q.empty() && q.back().first <= dp[j] - (j / w) * v) q.pop_back(); q.emplace_back(dp[j] - (j / w) * v, j); new_dp[j] = max(new_dp[j], q.front().first + (j / w) * v); } } dp = move(new_dp); } cout << dp[S] << endl; 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...