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;
long long delivery(int N, int K, int L, int a[]) {
long long ans = 0;
int n = N;
int k = K;
int l = 0, r = n - 1;
while((r - l + 1) >= k){
int mx = 0;
for (int i = l; i < l + k; i++) mx = max(mx, a[i]);
if (mx > (L - 1) / 2) break;
ans += 2 * mx;
l += k;
}
while ((r - l + 1) >= k){
int mn = 1e9;
for (int i = r; i > r - k; i--) mn = min(mn, a[i]);
if (mn <= (L - 1) / 2) break;
ans += 2 * (L - mn);
r -= k;
}
long long old = ans;
if ((r - l + 1) <= k) ans += L;
else ans += 2 * L;
int mx = 0;
for (int i = l; i <= r; i++){
if (a[i] > (L - 1) / 2) break;
mx = max(mx, a[i]);
}
int mn = L;
for (int i = r; i >= l; i--){
if (a[i] <= (L - 1) / 2) break;
mn = min(mn, a[i]);
}
ans = min(ans, old + 2 * mx + 2 * (L - mn));
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... |