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 pll pair<long long,long long>
#define all(v) v.begin(),v.end()
#define pb push_back
const long long maxn=1e6;
const long long minn=-1e6;
const long long inf=1e9+7;
int n,w[maxn],v[maxn],k[maxn],s;
ll dp[100001][2001];
void solve(){
dp[0][0]=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=s;j++){
dp[i][j]=dp[i-1][j];
if(j>=w[i]&&k[i]){
ll tg=dp[i][j];
dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);
if(tg>dp[i][j]) k[i]--;
}
}
}
cout<<dp[n][s];
}
main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>s>>n;
for(int i=1;i<=n;i++){
cin>>v[i]>>w[i]>>k[i];
}
solve();
// for(int i=1;i<=n;i++){
// cout<<v[i]<<" "<<w[i]<<" "<<k[i]<<endl;
// }
}
Compilation message (stderr)
knapsack.cpp:26:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
26 | main(){
| ^~~~
# | 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... |