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 <iostream>
#include <vector>
using namespace std;
const int maxn = 10000005;
int n, k, l;
int positions[maxn];
long long dp_left[maxn];
long long dp_right[maxn];
long long delivery(int N, int K, int L, int p[])
{
n = N;
k = K;
l = L;
for (int i = 1; i <= n; ++i)
{
positions[i] = p[i - 1];
}
dp_left[0] = 0;
dp_right[n + 1] = 0;
for (int i = 1; i <= n; ++i)
{
if (i <= k)
{
dp_left[i] = 2 * positions[i];
}
else
{
dp_left[i] = dp_left[i - k] + 2 * positions[i];
}
}
for (int i = n; i >= 1; --i)
{
if (n - i + 1 <= k)
{
dp_right[i] = 2 * (l - positions[i]);
}
else
{
dp_right[i] = dp_right[i + k] + 2 * (l - positions[i]);
}
}
long long ans = (1LL << 62);
if (n <= k)
{
ans = l;
}
for (int i = 0; i <= n; ++i)
{
ans = min(ans, dp_left[i] + dp_right[i + 1]);
}
for (int i = 0; i <= n; ++i)
{
if (i + k + 1 > n + 1)
{
break;
}
ans = min(ans, dp_left[i] + l + dp_right[i + k + 1]);
}
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... |