Submission #478011

#TimeUsernameProblemLanguageResultExecution timeMemory
478011pavanscodingKnapsack (NOI18_knapsack)C++17
37 / 100
1091 ms1100 KiB
#include <algorithm> #include <bits/stdc++.h> #include <cstring> using namespace std; const int mod=1e9+7; int dp[100001][2001],s,n,v[100001],w[100001],k[100001]; 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=0;j<=s;j++){ for(int t=0;t<=k[i];t++){ if(j>=t*w[i]) dp[i][j]=max(dp[i][j],dp[i-1][j-t*w[i]]+t*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...