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 main() {
int S, N;
cin >> S >> N;
vector<int> value(N), weight(N), amount(N);
for (int i = 0; i < N; i++)
cin >> value[i] >> weight[i] >> amount[i];
vector<vector<pair<int, int>>> dp(N, vector<pair<int, int>>(S + 1));
for (int i = 0; i < N; i++) {
for (int j = 0; j <= S; j++) {
int k = j + weight[i];
if (dp[i][j].second < amount[i] && k <= S) {
if (dp[i][k].first < dp[i][j].first + value[i]) {
dp[i][k].first = dp[i][j].first + value[i];
dp[i][k].second = dp[i][j].second + 1;
}
}
if (i < N - 1 && dp[i + 1][j].first < dp[i][j].first) {
dp[i + 1][j].first = dp[i][j].first;
}
}
}
int ans = 0;
for (int i = 0; i < N; i++)
for (int j = 0; j <= S; j++)
ans = max(ans, dp[i][j].first);
cout << ans << '\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... |