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;
const long long INF = 1e18;
long long delivery(int N, int K, int L, int p[])
{
long long a[N + 1];
for(int i = 1; i <= N; i++)
{
a[i] = p[i - 1];
}
long long pref[N + 2], suf[N + 2];
pref[0] = 0;
for(int i = 1; i <= N; i++)
{
pref[i] = (i <= K) ? a[i] * 2LL : a[i] * 2LL + pref[i - K];
}
suf[N + 1] = 0;
for(int i = N; i > 0; i--)
{
suf[i] = (i + K - 1 > N) ? (L - a[i]) * 2LL : (L - a[i]) * 2LL + suf[i + K];
}
long long ans = suf[1];
for(int i = 0; i <= N; i++)
{
ans = min(ans, pref[i] + suf[i + 1]);
if(i + K <= N)
{
ans = min(ans, pref[i] + L + suf[i + K + 1]);
}
else
{
ans = min(ans, pref[i] + L);
}
}
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... |