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 <bits/stdc++.h>
#define forint(i, N) for (int i = 0; i < (N); i++)
using namespace std;
typedef long long ll;
ll delivery(int n, int k, int l, int p[]) {
vector<int> dist(n);
for (int i = 0; i < n; i++) {
dist[i] = min(p[i], l - p[i]);
}
vector<ll> costl(n);
vector<ll> costr(n);
int a = 1;
costl[0] = 2 * dist[0];
for (int i = 1; i < n; i++) {
costl[i] = (ll)(costl[i - 1] + 2 * (p[i] - p[i - 1]));
if (a == 0) costl[i] += (ll)dist[i];
if (a == k) a = 0;
}
a = 1;
costr[n - 1] = 2 * dist[n - 1];
for (int i = n - 2; i >= 0; i--) {
costr[i] = (ll)(costr[i + 1] + 2 * (p[i + 1] - p[i]));
if (a == 0) costr[i] += (ll)dist[i];
if (a == k) a = 0;
}
ll ret = min(costl[n - 1], costr[0]);
forint(i, n - 1) {
if (costl[i] + costr[i + 1] < ret) ret = costl[i] + costr[i + 1];
}
return ret;
}
# | 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... |