Submission #638016

#TimeUsernameProblemLanguageResultExecution timeMemory
638016zandlerKnapsack (NOI18_knapsack)C++14
37 / 100
1090 ms340 KiB
#include <bits/stdc++.h> #define int long long using namespace std; int dp[2001]; // first i considered, j space taken int c[2001]; int v[2001]; int k[2001]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int s, n; cin >> s >> n; for(int i=0;i<n;i++){ cin >> v[i] >> c[i] >> k[i]; } for(int i=0;i<n;i++){ for(int j=s;j>=0;j--){ for(int x=k[i]; x>=1; x--){ if(j+x*c[i] <= s){ dp[j+x*c[i]]=max(dp[j+x*c[i]],dp[j]+v[i]*x); } } } } cout << *max_element(dp,dp+s+1) << '\n'; return 0; }
#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...