This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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++){
int dq[2005][2];
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][1]< q-mn) head++;
while(tail-head>0 && dq[tail-1][0] <=dp[j]-q*v) tail--;
dq[tail][0] = dp[j]-q*v;
dq[tail][1] = q;
tail++;
dp[j]=dq[head][0]+q*v;
}
}
}
cout<<dp[s]<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |