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 rep(i , j , k) for (int i = j; i < (int)k; i++)
typedef long long ll;
typedef vector<ll> vl;
ll delivery(int N, int K, int Ll, int p[]) {
sort(p , p + N);
vl L(N) , R(N);
rep(i , 0 , N) {
L[i] = p[i];
if (i >= K)
L[i] += L[i - K];
}
for (int i = N - 1; ~i; i--) {
R[i] = Ll - p[i];
if (i + K < N)
R[i] += R[i + K];
}
ll ans = 2 * L[N - 1] - max(0 , Ll - 2 * p[N - 1]);
ans = min(ans , 2 * R[0] - max(0 , 2 * p[0] - Ll));
rep(i , 1 , N)
ans = min(ans , 2 * (L[i - 1] + R[i]) - max(0 , max(Ll - 2 * p[i - 1] , 2 * p[i] - Ll))) ;
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... |