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 n, m, w[105], a[105], v[105], dp[105][10005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> m >> n;
for(int i = 1; i <= n; ++i) {
cin >> w[i] >> v[i] >> a[i];
}
for(int i = 1; i <= n; ++i)
for(int j = 1; j <= m; ++j) {
dp[i][j] = dp[i - 1][j];
for(int k = 1, lim = min(a[i], j / w[i]); k <= lim; ++k)
dp[i][j] = max(dp[i][j], dp[i - 1][j - w[i] * k] + v[i] * k);
}
cout << (*max_element(dp[n] + 1, dp[n] + m + 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... |