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;
ll delivery(int n, int k, int l, int p[]) {
ll opa = 0;
int res = 0;
int s = 0;
for (int i = 0; i < n; i++) {
if (res == k-1 || i == n-1) {
if (res == 0) s = p[i];
if (s <= l/2-1) {
opa += min(l, 2*p[i]);
}
else {
opa += 2*(l-s);
}
res = 0;
continue;
}
if (res == 0) {
s = p[i];
res++;
continue;
}
res++;
}
if (k == 1) return opa;
ll opb = 0;
res = 0;
s = 0;
for (int i = n-1; i >= 0; i--) {
if (res == k-1 || i == 0) {
if (res == 0) s = p[i];
if (s > l/2-1) {
opb += min(l, 2*(l-p[i]));
}
else {
opb += 2*s;
}
res = 0;
continue;
}
if (res == 0) {
s = p[i];
res++;
continue;
}
res++;
}
ll opc = 0;
res = 0;
for (int i = 0; i < n && p[i] <= l/2-1; i++) {
if (res == k-1 || i == n-1 || p[i+1] > l/2-1) {
opc += 2*p[i];
res = 0;
continue;
}
res++;
}
for (int i = n-1; i >= 0 && p[i] > l/2-1; i--) {
if (res == k-1 || i == 0 || p[i-1] <= l/2-1) {
opc += 2*(l-p[i]);
res = 0;
continue;
}
res++;
}
return min(min(opa, opa), opc);
}
# | 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... |