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 "boxes.h"
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e18;
template <class T> struct MinDeque {
int lo = 0, hi = -1;
std::deque<std::pair<T, int>> d;
void ins(T x) { // add to back
while ((d).size() && d.back().first >= x) d.pop_back();
d.push_back({x, ++hi});
}
void del() { // delete from front
if (d.front().second == lo++) d.pop_front();
}
T get() {
return (d).size() ? d.front().first : std::numeric_limits<T>::max();
}
};
long long delivery(int N, int K, int L, int p[]) {
using namespace std;
ll ans = INF;
MinDeque<ll> D1;
MinDeque<ll> D2;
D1.ins(0);
D2.ins(2 * (L-p[0]));
for (int i = 0; i < N; i++) {
ll res = INF;
res = min(res, D2.get());
res = min(res, D1.get() + min(L, 2*p[i]));
if (i != N-1) {
D1.ins(res);
D2.ins(res+2*L-2*p[i+1]);
}
if (i >= K-1 && i != N-1) {
D1.del();
D2.del();
}
if (i == N-1) ans = res;
}
return ans;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |