Submission #833064

#TimeUsernameProblemLanguageResultExecution timeMemory
833064gunasaimaheshKnapsack (NOI18_knapsack)C++17
37 / 100
1034 ms1116 KiB
#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 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...