제출 #867431

#제출 시각아이디문제언어결과실행 시간메모리
867431Kak008723Knapsack (NOI18_knapsack)C++14
73 / 100
1062 ms600 KiB
#include<bits/stdc++.h> using namespace std; int s,n,dp[2005]; int main(){ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>s>>n; for(int i=1;i<=n;i++){ int v,w,k; cin>>v>>w>>k; for(int r=0;r<w;r++){ pair<int,int> dq[2005]; int head = 0 , tail = 0; for(int q = 0 ,j=r;j<=s;q++,j+=w){ int mn = min(q,k); while(tail-head>0 && dq[head].second< q-mn) head++; while(tail-head>0 && dq[tail-1].first <=dp[j]-q*v) tail--; dq[tail].first = dp[j]-q*v; dq[tail].second = q; tail++; dp[j]=dq[head].first+q*v; } } } cout<<dp[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...