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;
typedef long long ll;
struct item {
ll v, w, k;
};
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
ll s, n; cin >> s >> n;
vector<item> v(n);
for (ll i = 0; i < n; ++i) {
cin >> v[i].v >> v[i].w >> v[i].k;
}
vector<ll> best(s + 1);
for (ll i = 0; i < n; ++i) {
ll fr = 0;
ll bfr = best[fr];
for (ll j = 0; j <= s; ++j) {
ll o = bfr + v[i].v * min((j - fr) / v[i].w, v[i].k);
if (best[j] > o || (best[j] == o && j - fr % 4 == 0)) {
fr = j;
bfr = best[fr];
}
if (j != 0) best[j] = max(best[j], best[j - 1]);
best[j] = max(best[j], bfr + v[i].v * min((j - fr) / v[i].w, v[i].k));
}
}
cout << *max_element(best.begin(), best.end()) << '\n';
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... |