Submission #997782

#TimeUsernameProblemLanguageResultExecution timeMemory
997782amirhoseinfar1385Knapsack (NOI18_knapsack)C++17
37 / 100
8 ms604 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=100000+10,maxs=2000+10; int dp0[maxs],dp1[maxs],val[maxn],ted[maxn],n,s,pr[maxn]; void vorod(){ cin>>s>>n; for(int i=0;i<n;i++){ cin>>val[i]>>pr[i]>>ted[i]; } } void solve(){ for(int i=0;i<n;i++){ for(int j=0;j<pr[i];j++){ int now=0; deque<int>dq; //dq.push_back(0); for(int h=j;h<=s;h+=pr[i]){ dp0[h]-=now*val[i]; now++; while((int)dq.size()>0&&dq.back()<dp0[h]){ dq.pop_back(); } dq.push_back(dp0[h]); if(h-(ted[i]+1)*pr[i]>=0){ if(dq.front()==dp0[h-(ted[i]+1)*pr[i]]){ dq.pop_front(); } } dp1[h]=dq.front()+(now-1)*val[i]; } } for(int j=0;j<=s;j++){ swap(dp1[j],dp0[j]); if(j>=1){ dp0[j]=max(dp0[j],dp0[j-1]); } dp1[j]=0; } } } int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); vorod(); solve(); cout<<dp0[s]<<endl; }
#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...