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;
typedef long long ll;
#define all(v) v.begin(), v.end()
long long delivery(int N, int K, int L, int p[]) {
ll n = N;
ll k = K;
ll l = L;
vector<ll> v(p, p + N);
ll dist = 0;
ll s = 0, e = n;
for (ll i = k - 1; i < n && v[i] <= l / 2; i += k) {
dist += 2 * v[i];
s = i + 1;
}
for (ll i = n - k; i >= 0 && v[i] > l / 2; i -= k) {
dist += 2 * (l - v[i]);
e = i;
}
ll a = 0;
for (ll i = s; i < n && v[i] <= l / 2; i++) {
a = 2 * v[i];
}
ll b = 0;
for (ll i = e - 1; i >= 0 && v[i] > l / 2; i--) {
b = 2 * (l - v[i]);
}
ll mxs, mxe, mx = -1;
for (ll i = 0; i < n - k; i++) {
if(i <= s && i + k >= e){
if(p[i + k - 1] - p[i] > mx){
mx = p[i + k - 1] - p[i];
mxs = i;
mxe = i + k - 1;
}
}
}
if(mx == -1) return dist + a + b;
ll sub = l + (p[mxs] - p[s]) + (p[e] - p[mxe]);
return min(dist + a + b, dist + sub);
}
# | 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... |