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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int s, n;
cin >> s >> n;
vector<vector<pair<int, int>>> v(s + 1);
for (int i = 0; i < n; i++) {
int vv, w, k;
cin >> vv >> w >> k;
v[w].emplace_back(vv, k);
}
vector<int> a, w;
for (int i = 1; i <= s; i++) {
sort(v[i].rbegin(), v[i].rend());
for (int j = 0, k = 0; k < (int) v[i].size() && j < s / i; j++) {
v[i][k].second -= 1;
a.push_back(v[i][k].first);
w.push_back(i);
if (v[i][k].second == 0) {
k++;
}
}
}
vector<int> dp(s + 1, 0);
n = a.size();
for (int i = 0; i < n; i++) {
for (int j = s; j >= w[i]; j--) {
dp[j] = max(dp[j], a[i] + dp[j - w[i]]);
}
}
cout << *max_element(dp.begin(), dp.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... |