#include "boxes.h"
#include <bits/stdc++.h>
using namespace std;
const int M = 10000005;
const long long INF = 1e18;
long long f1[M], f2[M], f3[M];
long long delivery(int N, int K, int L, int p[]) {
int pos = -1;
for (int i = 0; i < N; ++i) {
if (p[i] * 2 <= L) pos = i;
}
int cnt;
long long sum;
cnt = 0, sum = 0;
for (int i = 0; i <= pos; ++i) {
++cnt;
if (pos - i + 1 > K) {
if (cnt == K) sum += p[i] * 2, cnt = 0;
}
else {
f1[pos - i] = sum + p[i] * 2;
}
}
cnt = 0, sum = 0;
for (int i = N - 1; i > pos; --i) {
++cnt;
if (i - pos > K) {
if (cnt == K) sum += (L - p[i]) * 2, cnt = 0;
}
else {
f2[i - pos - 1] = sum + (L - p[i]) * 2;
}
}
f3[0] = f1[0];
for (int i = 1; i < K; ++i) {
f3[i] = min(f3[i - 1], f1[i]);
}
long long res = INF;
res = min(res, f3[0] + f2[0]);
for (int i = 0; i < K; ++i) {
res = min(res, f3[K - i] + f2[i] + L);
}
return res;
}
# |
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 |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 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 |
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 |
- |
# |
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 |
- |