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;
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int s, n; cin >> s >> n;
vector<int> dp(s + 1);
vector<vector<array<int, 2>>> cands(s);
while (n--) {
int v, w, k; cin >> v >> w >> k;
cands[--w].push_back({v, k});
}
vector<array<int, 2>> items;
for (int w = 0; w < s; ++w) {
sort(cands[w].begin(), cands[w].end());
int cnt = s / (w + 1);
while (cands[w].size() && cnt) {
auto [x, y] = cands[w].back(); cands[w].pop_back();
int k = min(y, cnt);
while (k--) {
--cnt;
items.push_back({w + 1, x});
}
}
}
for (auto [w, x] : items) {
for (int j = s; j >= w; --j) {
dp[j] = max(dp[j], dp[j - w] + x);
}
}
cout << *max_element(dp.begin(), dp.end());
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... |