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 <cstring>
#include <iostream>
using namespace std;
int s, n, w[100001], v[100001], k[100001];
int dp[2001];
int main() {
// freopen("debug.cerr", "w", stderr);
memset(dp, 0, sizeof(dp));
cin >> s >> n;
for (int i = 1; i <= n; i++) {
cin >> v[i] >> w[i] >> k[i];
}
// for (int i = 1; i <= n; i++)
// cerr << k[i] << ' ';
// cerr << endl;
for (int i = 1; i <= n; i++) {
for (int j = s; j >= 1; j--) {
for (int l = 1; l <= k[i] && l * w[i] <= j; l++) {
dp[j] = max(dp[j], dp[j - l * w[i]] + l * v[i]);
}
}
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= s; j++) {
// cerr << dp[i][j] << '\t';
// }
// cerr << 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... |