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;
signed main() {
cin.tie(nullptr)->sync_with_stdio(false);
int s, n; cin >> s >> n;
vector<vector<pair<int, int>>> items(s + 1);
for (int i = 0; i < n; ++i) {
int v, w, k; cin >> v >> w >> k;
items[w].emplace_back(v, k);
}
vector<pair<int, int>> a;
for (int w = 1; w <= s; ++w) {
sort(items[w].begin(), items[w].end(), greater<>());
int cnt = s / w;
for (pair<int, int> p: items[w]) {
int bound = min(p.second, cnt);
for (int i = 1; i <= bound; ++i) {
a.emplace_back(w, p.first);
}
cnt -= bound;
if (cnt == 0) break;
}
}
vector<long long> dp(s + 1);
for (pair<int, int> p: a) {
for (int w = s; w >= p.first; --w) {
dp[w] = max(dp[w], dp[w - p.first] + p.second);
}
}
cout << *max_element(dp.begin(), dp.end());
}
# | 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... |