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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll x, ans;
vector<ll> arr, A, B;
ll delivery(int N, int K, int L, int positions[]) {
arr.resize(N + 2);
for (int i = 1; i <= N; i++) arr[i] = positions[i - 1];
A.resize(N + 2); B.resize(N + 2);
for (int i = 0; i <= N; i++) {
if (i <= K) A[i] = arr[i] * 2;
else A[i] = arr[i] * 2 + A[i - K];
}
for (int i = N; i; i--) {
if (i >= N + 1 - K) B[i] = (L - arr[i]) * 2;
else B[i] = (L - arr[i]) * 2 + B[i + K];
}
ans = 198765432198765432;
for (int i = 0; i <= N; i++)
ans = min(ans, A[i] + B[i + 1]);
for (int i = 0; i <= N; i++) {
if(i + 1 + K <= N + 1)
ans = min(ans, A[i] + L + B[i + 1 + K]);
}
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... |