#include <bits/stdc++.h>
#include "boxes.h"
using namespace std;
const int maxn = 2e7+10;
typedef long long ll;
int n, k;
int p[maxn];
ll pref[maxn], suf[maxn];
long long delivery(int N, int K, int L, int positions[])
{
n = N, k = K;
for (int i = 1; i <= n; i++)
p[i] = positions[i-1];
int mid = L/2;
int last_p = 0, last_s = 0;
if (p[1] <= mid) pref[1] = 2ll*p[1], last_p = 1;
for (int i = 2; i <= n; i++)
{
if (p[i] > mid) break;
pref[i] = 2ll*p[i] + pref[max(0, i-k)];
last_p = i;
}
if (p[n] > mid) suf[n] = 2ll*(L-p[n]), last_s = n;
for (int i = n-1; i >= 1; i--)
{
if (p[i] <= mid) break;
suf[i] = 2ll*(L-p[i]) + suf[i+k];
last_s = i;
}
ll ans = pref[last_p] + suf[last_s];
for (int i = 1; i <= n; i++)
{
ll aux = 1ll*i*L;
for (int j = 1; j <= k; j++)
{
if (!last_p && !last_s) break;
else if (!last_p) last_s++;
else if (!last_s) last_p--;
else if (p[last_p] > L-p[last_s]) last_p--;
else last_s++;
}
aux += pref[last_p]+suf[last_s];
ans = min(ans, aux);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
384 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
3 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Incorrect |
5 ms |
384 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |