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;
const int MAXX = 1e5 + 5;
int s,n,v[MAXX],w[MAXX],dp[2001][MAXX],k[MAXX];
int main(){
cin >> s >> n;
for (int i = 0; i < n; i++) cin >> v[i] >> w[i] >> k[i];
for (int i = 1; i <= s; i++){
for (int j = 0; j < n; j++){
if (i >= w[j]){
int num = 1;
while (num*w[j] <= i && num <= k[j]){
dp[i][j] = max(max(dp[i - num*w[j]][j - 1] + v[j]*num,dp[i][j]),max(dp[i - 1][j],dp[i][j - 1]));
dp[i][j] = max(dp[i][j],dp[i-1][j - 1]);
num++;
}
}
}
}
cout << dp[s][n - 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... |