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;
typedef long long ll;
int main()
{
int s,n;
cin>>s>>n;
vector<int> v(n);
vector<int> w(n);
vector<int> k(n);
for(int i=0;i<n;i++){
cin>>v[i]>>w[i]>>k[i];
}
vector<vector<int>> dp(n+1,vector<int>(s+1));
for(int i=0;i<=n;i++){
dp[i][0]=0;
}
for(int i=1;i<=n;i++){
for(int j=1;j<=s;j++){
int ans=INT_MIN;
for(int p=0;p<=k[i-1];p++){
if(j>=p*w[i-1]){
ans=max(ans,p*v[i-1]+dp[i-1][j-p*w[i-1]]);
}
}
dp[i][j]=ans;
}
}
cout<<dp[n][s]<<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... |