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;
const long long INF = 1e18;
template <class T1, class T2>
inline bool minimise(T1 &x, T2 y) {
if (x > y) { x = y; return true; }
return false;
}
long long delivery(int N, int K, int L, int pos[]) {
vector<int> lefts, rights;
for (int i = 0; i < N; i++) {
if (2 * pos[i] < L)
lefts.push_back(pos[i]);
else
rights.push_back(L - pos[i]);
}
sort(lefts.begin(), lefts.end(), greater<int>());
sort(rights.begin(), rights.end(), greater<int>());
vector<long long> sum_lefts(lefts.size()), sum_rights(rights.size());
for (int i = int(lefts.size() - 1); i >= 0; i--) {
sum_lefts[i] = lefts[i];
if (i + K < int(lefts.size()))
sum_lefts[i] += sum_lefts[i + K];
}
for (int i = int(rights.size() - 1); i >= 0; i--) {
sum_rights[i] = rights[i];
if (i + K < int(rights.size()))
sum_rights[i] += sum_rights[i + K];
}
long long ans = INF;
for (int i = 0; i <= K; i++) {
long long cur = 1LL * L;
if (i < int(lefts.size()))
cur += 2 * sum_lefts[i];
if (K - i < int(rights.size()))
cur += 2 * sum_rights[K - i];
minimise(ans, cur);
}
return ans;
}
# | 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... |