Submission #1124789

#TimeUsernameProblemLanguageResultExecution timeMemory
1124789dwuyKnapsack (NOI18_knapsack)C++17
73 / 100
1095 ms2628 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MX = 100005; int S, n; int v[MX], w[MX], k[MX]; int f[2005]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(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++){ k[i] = min(k[i], S/w[i]); for(int t=1; k[i]>0; t=min(k[i], t<<1)){ int val = v[i]*t; int wei = w[i]*t; for(int j=S; j>=wei; j--){ f[j] = max(f[j], f[j-wei] + val); } k[i] -= t; } } cout << *max_element(f + 0, f + S + 1); 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...