This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
#define all(x) x.begin(), x.end()
#define L(i, b, e) for (int i = b; i < e; ++i)
#define R(i, b, e) for (int i = b; i >= e; --i)
#define pb emplace_back
#define vi vector<int>
#define sz(x) ((int) x.size())
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int s, n;
cin >> s >> n;
vi v(n), w(n), k(n);
L(i, 0, n){
cin >> v[i] >> w[i] >> k[i];
}
vector<i64> dp(s + 1, -1);
dp[0] = 0;
L(i, 0, n){
L(j, 0, w[i]){
deque<pair<i64, int>> dq;
int c = 0;
for (int p = j; p <= s; p += w[i]){
while (!dq.empty() && c - dq.front().second > k[i])dq.pop_front();
i64 t = dp[p];
if (!dq.empty()){
dp[p] = max(dp[p], dq.front().first + 1LL * dq.front().second * v[i] + 1LL * (c - dq.front().second) * v[i]);
}
if (t != -1){
i64 m = t - 1LL * c * v[i];
while (!dq.empty() && dq.back().first <= m)dq.pop_back();
dq.push_back({m, c});
}
c++;
}
}
}
cout << *max_element(all(dp));
}
# | 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... |