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>
using namespace std;
#define int int64_t
long long delivery(signed N, signed K, signed L, signed p[]) {
vector<int> left, right;
for (int i = 0; i<N; i++) {
if (p[i] <= L/2) left.push_back(p[i]);
else right.push_back(L-p[i]);
}
sort(left.begin(), left.end());
sort(right.begin(), right.end());
auto leftO = left;
auto rightO = right;
long long res1 = L;
for (int i = 0; i<K; i++) {
if ((left.size() && right.empty()) || (left.size() && left.back() > right.back())) {
left.pop_back();
} else if (right.size()) {
right.pop_back();
}
}
while (left.size()) {
res1 += left.back()*2;
for (int i = 0; i<K; i++) {
if (left.size()) left.pop_back();
}
}
while (right.size()) {
res1 += right.back()*2;
for (int i = 0; i<K; i++) {
if (right.size()) right.pop_back();
}
}
left = leftO;
right = rightO;
long long res2 = 0;
while (left.size()) {
res2 += left.back()*2;
for (int i = 0; i<K; i++) {
if (left.size()) left.pop_back();
}
}
while (right.size()) {
res2 += right.back()*2;
for (int i = 0; i<K; i++) {
if (right.size()) right.pop_back();
}
}
return min(res1, res2);
}
# | 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... |