Submission #465054

#TimeUsernameProblemLanguageResultExecution timeMemory
465054Qw3rTyKnapsack (NOI18_knapsack)C++11
37 / 100
2 ms460 KiB
#include <bits/stdc++.h> #define pi pair<int,int> #define fi first #define se second #define pb push_back using namespace std; const int maxN = 1e5+5; const int maxV = 2e3+5; vector<int> d[maxV]; int S,N; int f[maxV]; signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); //freopen("../test.in","r",stdin); cin >> S >> N; for(int i = 1; i <= N; ++i){ int v,w,k; cin >> v >> w >> k; for(int j = 1; j <= k; j <<= 1){ if(w * j > S || k < j)break; k -= j; d[w*j].pb(v*j); } if(k > 0 && w * k <= S)d[w*k].pb(v*k); } for(int i = 1; i <= S; ++i){ if(d[i].size()){ sort(d[i].begin(),d[i].end(),greater<int>()); //Consider only the first floor(S/W) objects int num = min(S/i,(int)(d[i].size())); for(int j = 0; j < num; ++j){ for(int k = S; k >= i; --k){ f[k] = max(f[k],f[k-i] + d[i][j]); } } } } cout << f[S] << '\n'; }
#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...