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>
#define int long long
using namespace std;
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int S,n;
cin>>S>>n;
int V[n+1];
int W[n+1];
int K[n+1];
for(int i=1;i<=n;i++)cin>>V[i]>>W[i]>>K[i];
if(n==1){
cout<<min(K[1],S/W[1])*V[1];
return 0;
}
int ok=1;
for(int i=1;i<=n;i++)if(K[i]!=1)ok=0;
if(ok){
int dp[n+1][S+1];
for(int i=0;i<=n;i++)for(int j=0;j<=S;j++)dp[i][j]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=S;j++)dp[i][j]=dp[i-1][j];
for(int j=W[i];j<=S;j++){
dp[i][j]=max(dp[i][j],dp[i-1][j-W[i]]+V[i]);
}
}
int ans=0;
for(int i=1;i<=S;i++){
ans=max(ans,dp[n][i]);
}
cout<<ans;
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... |