#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
deque<ll> pd;
deque<ll> dpd;
void addElement(ll el, deque<ll> &d){
while (d.size()>0&&d.back()>el){
d.pop_back();
}
d.push_back(el);
}
void removeElement(ll el, deque<ll> &d){
if (d.front()==el){
d.pop_front();
}
}
long long delivery(int N, int K, int L, int p[]) {
ll n = N, k=K, l=L;
vector<ll> dp(n+1,0);
//multiset<ll> pset;
//multiset<ll> dpset;
for (ll i = 1; i<=n; i++){
/*ll minval = -1;
for (ll j = max((i-k+1),0LL); j<=i; j++){
//from j to i inclusive.
ll val = min((l-p[j])*2LL,min(l,p[i]*2LL));
if (j>0){
val+=dp[j-1];
}
if (minval==-1||minval>val){
minval=val;
}
}*/
addElement((l-p[i-1])*2+dp[i-1],pd);
addElement(dp[i-1],dpd);
if (i-k-1>=0){
ll prem=(l-p[i-k-1])*2;
prem+=dp[i-k-1];
ll dprem=dp[i-k-1];
removeElement(dprem,dpd);
removeElement(prem,pd);
}
//cout<<"pset ";for (ll it : pset){cout<<it<<" ";}cout<<endl;
//cout<<"dpset ";for (ll it : dpset){cout<<it<<" ";}cout<<endl;
ll a=0,b=l,c=p[i-1]*2;
if (pd.size()>0){
a = pd.front();
}
if (dpd.size()>0){
b+=dpd.front();
}
dp[i]=min(min(a,b),c);
//cout<<dp[i]<<endl;
}
return dp[n];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
372 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |