#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |