#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.back()>el&&d.size()>0){
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 = pd.front();
ll b = dpd.front()+l;
ll c = dpd.front()+p[i-1]*2;
dp[i]=min(min(a,b),c);
//cout<<dp[i]<<endl;
}
return dp[n];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |