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
#define pb push_back
#define mp make_pair
const ll MAXN = 1e6+5;
const ll INF = 1e5+5;
const ll MOD = 1e9+7;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll s,n;
cin>>s>>n;
ll v,w,k;
ll obj[n+1][3];
for(int i=1;i<=n;i++){
cin>>v>>w>>k;
obj[i][0]=v;
obj[i][1]=w;
obj[i][2]=k;
}
ll dp[n+1][s+1];
for(int j=0;j<=s;j++)dp[0][j]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=s;j++){
dp[i][j]=0;
for(ll freq=0;freq<=obj[i][2];freq++){
if(j-freq*obj[i][1]<0)break;
dp[i][j] = max(dp[i][j] , dp[i-1][j-freq*obj[i][1]]+freq*obj[i][0]);
}
}
}
cout<<dp[n][s]<<'\n';
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... |