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>
long long dist(long long place, int L) {
return std::min(place, (long long) L - place);
}
struct Range {
int l, r;
long long get(int L, int pos[]) {
long long res = dist(pos[l], L) + dist(pos[r], L);
int pl = pos[l];
int pr = pos[r];
if (pl > pr) {
std::swap(pl, pr);
}
res += pr - pl;
return res;
}
};
long long delivery(int n, int k, int L, int pos[]) {
std::sort(pos, pos + n);
long long ans = 1LL << 60;
for (int sl = k; sl > 0; sl--) {
long long now = 0;
int l = sl;
std::vector <std::pair <int, int>> here;
{
here.emplace_back(0, l - 1);
Range range = { 0, l - 1 };
now += range.get(L, pos);
}
while (l < n) {
int r = std::min(l + k - 1, n - 1);
here.emplace_back(l, r);
Range range = { l, r };
now += range.get(L, pos);
l += k;
}
ans = std::min(ans, now);
}
return ans;
}
//int main() {
//int a[3] = { 1, 2, 5 };
//std::cout << delivery(3, 2, 8, a) << std::endl;
//}
# | 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... |