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;
#define ll long long
int main(){
int s, n; cin>>s>>n;
vector<int> v(n+1);
vector<int> w(n+1);
vector<int> k(n+1);
vector<vector<long long>> dp(s+1, vector<long long>(n+1, 0));
for (int i=1; i<=n; i++){
cin>>v[i]>>w[i]>>k[i];
}
cout<<k[1]<<endl;
for (int i=1; i<=n; i++){
for (int m=1; m<=k[i]; m++){
for (int j=s; j>=0; j--){
if(j-w[i]>=0) {
if(dp[j-w[i]][i-1]>0) dp[j][i] = max(dp[j][i], dp[j-w[i]][i-1]+v[i]);
if( dp[j-w[i]][i]>0 || (j-w[i]==0 && m==1)) dp[j][i] = max(dp[j][i], dp[j-w[i]][i]+v[i]);
}
}
}
for (int j=1; j<=s; j++) cout<<dp[j][i]<<" ";
cout<<endl;
}
ll cmax=0;
for (int j=s; j>0; j--){
if(dp[j][n]>0) {
cmax=max(cmax, dp[j][n]); break;
}
}
cout<<cmax;
}
# | 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... |