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() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
// 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, t = w[i]; l <= k[i] && t <= j; l++, t += w[i]) {
dp[j] = max(dp[j], dp[j - t] + t);
}
}
}
// for (int i = 1; i <= n; i++) {
// for (int j = 1; j <= s; j++) {
// cerr << dp[i][j] << '\t';
// }
// cerr << endl;
// }
cout << dp[s] << '\n';
}
# | 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... |