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 <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
cin.tie(0); iostream::sync_with_stdio(false);
int s, n; cin >> s >> n;
vector<vector<pair<int, int>>> que(s+1);
while (n--) {
int v, w, k; cin >> v >> w >> k;
k = min(k, s / w);
que[w].push_back(pair(v, k));
}
vector<int> best(s+1);
for (int w = 1; w <= s; ++w) {
auto& v = que[w];
sort(v.begin(), v.end(), greater<>{});
int rem = s/w;
for (auto [v, k] : v) {
if (!rem) {
break;
}
for (; k && rem; k--, rem--) {
for (int i = s-w; i >= 0; --i) {
auto& r = best[i+w];
r = max(r, best[i] + v);
}
}
}
}
cout << best[s] << endl;
}
# | 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... |