Submission #562936

#TimeUsernameProblemLanguageResultExecution timeMemory
562936pavanscodingKnapsack (NOI18_knapsack)C++17
73 / 100
491 ms262144 KiB
#include <bits/stdc++.h> using namespace std; const int mxn=1e5+1,mxs=2e3+1; int n,s,V[mxn],W[mxn],K[mxn],dp[mxn][mxs]; int main(){ cin.tie(0)->sync_with_stdio(0); cin >> s >> n; for(int i=1;i<=n;i++) cin >> V[i] >> W[i] >> K[i]; for(int i=1;i<=n;i++){ for(int j=1;j<=s;j++){ dp[i][j]=dp[i-1][j]; for(int k=1;k*W[i]<=j&&k<=K[i];k++) dp[i][j]=max(dp[i][j],dp[i-1][j-k*W[i]]+k*V[i]); } } cout << dp[n][s]; }
#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...