#include "boxes.h"
#include <bits/stdc++.h>
typedef long long ll;
const ll INF = 1e18;
struct MinDeque {
int lo = 0, hi = -1;
std::deque<std::pair<ll, int>> d;
void ins(ll 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();
}
ll get() {
return (d).size() ? d.front().first : INF;
}
};
long long delivery(int N, int K, int L, int p[]) {
using namespace std;
ll ans = INF;
MinDeque D1;
MinDeque 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-p[i+1]);
}
if (i >= K-1) {
D1.del();
D2.del();
}
if (i == N-1) ans = res;
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
364 KB |
Output is correct |
3 |
Correct |
0 ms |
364 KB |
Output is correct |
4 |
Incorrect |
0 ms |
364 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |