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> V(N), W(N), K(N);
for(int i = 0; i < N; i++) {
cin >> V[i] >> W[i] >> K[i];
}
vector<vector<int>> dp(2, vector<int>(S + 1));
for(int i /*item*/ = 0; i < N; i++) {
for(int w = 0; w <= S; w++) {
dp[1][w] = dp[0][w];
for(int k = 1; w - (k * W[i]) >= 0 && k <= K[i]; k++) {
dp[1][w] = max(dp[1][w], dp[0][w - (k * W[i])] + k * V[i]);
}
}
for(int w = 0; w <= S; w++) {
dp[0][w] = dp[1][w];
dp[1][w] = 0;
}
}
int mx = -1;
for(int i = 0; i <= S; i++) {
mx = max(mx, dp[0][i]);
}
cout << mx << "\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... |