Submission #1124791

#TimeUsernameProblemLanguageResultExecution timeMemory
1124791dwuyKnapsack (NOI18_knapsack)C++17
100 / 100
52 ms2888 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int MX = 2005; int S, n; int f[2005]; vector<pair<int, int>> G[2005]; int32_t main(){ ios_base::sync_with_stdio(false); cin.tie(0); cin >> S >> n; for(int i=1; i<=n; i++){ int v, w, k; cin >> v >> w >> k; G[w].push_back({v, k}); } for(int w=1; w<=S; w++){ sort(G[w].begin(), G[w].end(), greater<pair<int, int>>()); int lim = S/w; for(pair<int, int> p: G[w]){ int v, k; tie(v, k) = p; k = min(k, lim); lim -= k; for(int t=1; k>0; t=min(k, t<<1)){ int val = v*t; int wei = w*t; for(int j=S; j>=wei; j--){ f[j] = max(f[j], f[j-wei] + val); } k -= 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...