#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
vector <long long> costLeft;
vector <long long> costRight;
long long delivery (int N, int K, int L, int p[]) {
int mid = L >> 1;
for (int i = 0; i < N; ++i) {
if (p[i] > mid) {
costRight.push_back(2LL * (L - p[i]));
} else {
costLeft.push_back(2LL * p[i]);
}
}
reverse(costRight.begin(), costRight.end());
int sizeLeft = (int) costLeft.size();
int sizeRight = (int) costRight.size();
for (int i = K; i < sizeLeft; ++i) {
costLeft[i] += costLeft[i - K];
}
for (int i = K; i < sizeRight; ++i) {
costRight[i] += costRight[i - K];
}
long long ret = costLeft[sizeLeft - 1] + costRight[sizeRight - 1];
for (int i = 0; i <= K; ++i) {
int left = i, right = K - i;
long long leftCost = left >= sizeLeft ? 0 : costLeft[sizeLeft - 1 - left];
long long rightCost = right >= sizeRight ? 0 : costRight[sizeRight - 1 - right];
ret = min(ret, L + leftCost + rightCost);
}
return ret;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
476 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Runtime error |
2 ms |
508 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Runtime error |
2 ms |
376 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
476 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
476 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
476 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |