Submission #464835

#TimeUsernameProblemLanguageResultExecution timeMemory
464835Qw3rTyKnapsack (NOI18_knapsack)C++11
0 / 100
0 ms332 KiB
#include <bits/stdc++.h> #define int long long #define pi pair<int,int> #define fi first #define se second using namespace std; const int maxN = 1e5+5; const int maxV = 2e3+5; int cnt = 0; pi item[maxN*40]; //.fi = value; .se = weight; int id[maxN*40]; int baseVal[maxN]; int f[maxV]; int a[maxN]; int S,N; bool cmp(pi a, pi b){ return a.se > b.se; } 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; a[i] = k; baseVal[i] = v; int j = 1; while(j <= k){ item[++cnt] = pi(v*j,w*j); id[cnt] = i; j = j * 2; } } sort(item+1,item+cnt+1,cmp); for(int i = 1; i <= cnt; ++i){ for(int j = S; j >= item[i].se; --j){ if(f[j-item[i].se] + item[i].fi > f[j]){ //There are still this many items int amount = item[i].fi / baseVal[id[i]]; if(a[id[i]] >= amount){ a[id[i]] -= amount; f[j] = max(f[j], f[j-item[i].se] + item[i].fi); } } } } 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...