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;
//~ #define int long long
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int s, n;
cin >> s >> n;
vector<vector<int>> items(s+1);
for (int i = 0; i < n; i++) {
int v, w, k;
cin >> v >> w >> k;
int tmp = min(k, s/w);
for (int i = 0; i < tmp; i++) items[w].push_back(v);
}
vector<int> dp(s+1, 0);
for (int i = 1; i <= s; i++) {
sort(items[i].rbegin(), items[i].rend());
//~ cout << i << ": " << endl;
int tmp = items[i].size();
int sz = min(tmp, s/i);
for (int j = 0; j < sz; j++) {
int v = items[i][j];
//~ cout << j << " " << v << endl;
for (int k = s; k >= i; k--) {
dp[k] = max(dp[k], dp[k-i]+v);
//~ cout << "HERE: " << k << " " << dp[k] << endl;
}
}
}
cout << dp[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... |