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;
using ll = long long;
int v[100100], w[100100], k[100100];
int dp[2020];
vector<pair<int, int>> vec[2020];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int s, n;
cin >> s >> n;
for (int i = 1;i <= n;i++) {
cin >> v[i] >> w[i] >> k[i];
k[i] = min(k[i], s / w[i]);
vec[w[i]].push_back({ v[i], k[i] });
}
for (int i = 1;i <= s;i++) {
sort(vec[i].rbegin(), vec[i].rend());
int cnt = s / i;
int now = 0;
for (auto& x : vec[i]) {
while (x.second-- && ++now <= cnt) {
for (int j = 2000;j >= i;j--) {
dp[j] = max(dp[j], dp[j - i] + x.first);
}
}
if (now > cnt) break;
}
}
cout << (*max_element(dp, dp + s + 1));
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... |