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 N 10000002
using namespace std;
typedef long long ll;
int n, k, l, pos[N];
ll L[N], R[N], ans = 200000000000000000;
ll delivery(int N_, int K_, int L_, int positions[])
{
n = N_, k = K_, l = L_;
for(int i = 1; i <= n; i++) pos[i] = positions[i - 1];
for(int i = 1; i <= n; i++)
{
if(i <= k) L[i] = 2LL*(ll)pos[i];
else L[i] = L[i - k] + 2LL*(ll)pos[i];
}
for(int i = n; i >= 1; i--)
{
if(n - i + 1 <= k) R[i] = 2LL*((ll)l - (ll)pos[i]);
else R[i] = R[i + k] + 2LL*((ll)l -(ll) pos[i]);
}
ll d1 = min(pos[1], l - pos[1]), dn = min(pos[n], l - pos[n]);
ans = min((ll)R[1] - ((ll)l - (ll)pos[1]) + (ll)d1, (ll)L[n] - (ll)pos[n] + dn);
for(int i = 1; i < n; i++)
{
ll di = min(pos[i], l - pos[i]);
ll dii = min(pos[i + 1], l - pos[i + 1]);
ll A = (ll)L[i] - (ll)pos[i] + (ll)di;
ll B =(ll) R[i + 1] - ((ll)l - (ll)pos[i + 1]) + dii;
ans = min(ans, A + B);
}
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... |