Submission #944836

#TimeUsernameProblemLanguageResultExecution timeMemory
944836ezzzayKnapsack (NOI18_knapsack)C++14
37 / 100
1061 ms7516 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define ff first #define ss second #define pb push_back const int N=3e5+2; int dp[N]; int v[N],w[N],k[N]; signed main(){ int s,n; cin>>s>>n; for(int i=1;i<=n;i++){ cin>>v[i]>>w[i]>>k[i]; } for(int i=0;i<N;i++)dp[i]=-1; dp[0]=0; for(int i=1;i<=n;i++){ for(int p=0;p<k[i];p++){ for(int j=s;j>=w[i];j--){ if(dp[j-w[i]]!=-1){ dp[j]=max(dp[j],dp[j-w[i]]+v[i]); } } } } int ans=0; for(int i=0;i<N;i++)ans=max(ans,dp[i]); cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...