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 <iostream>
#include <algorithm>
using namespace std;
int main(){
int s, n, ans = 0;
cin >> s >> n;
int v[n], w[n], k[n];
int dp[n+1][s+1];
for(int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i];
for(int i = 0; i <= n; i++){
for(int j = 0; j<= s; j++){
dp[i][j] = -1;
}
}
dp[0][0] = 0;
for(int i = 0; i < n; i++){
for(int j = 0; j<= s; j++){
if (dp[i][j] == -1) continue;
for(int l = 0; l <= k[i]; l++){
if (j+l*w[i] > s) break;
dp[i+1][j+l*w[i]] = max(dp[i+1][j+l*w[i]], dp[i][j] + l*v[i]);
ans = max (ans, dp[i+1][j+l*w[i]]);
}
}
}
cout << ans << 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... |