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(){
ios_base::sync_with_stdio(false);
cin.tie(0);
long long s, n, ans = 0;
cin >> s >> n;
long long v[n], w[n], k[n];
long long dp[n+1][s+1];
for(long long i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i];
for(long long i = 0; i <= n; i++){
for(long long j = 0; j<= s; j++){
dp[i][j] = -1;
}
}
dp[0][0] = 0;
for(long long i = 0; i < n; i++){
for(long long j = 0; j<= s; j++){
if (dp[i][j] == -1) continue;
for(long long 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... |