#include <bits/stdc++.h>
#include "boxes.h"
const int MAX_N = 10000000;
long long pref[1+MAX_N], suff[1+MAX_N];
long long cost(int i, int j, int l, int k, int n) {
return pref[i] + suff[j] + (long long)(n - i - j + k - 1) / k * l;
}
long long delivery(int n, int k, int l, int p[]) {
long long rez = 1LL << 60;
if(n > 1000)
return 0LL;
for(int i = 1; i <= n; ++i) {
if(i - k >= 0)
pref[i] = pref[i - k];
pref[i] = pref[i] + p[i - 1] * 2;
}
for(int i = 1; i <= n; ++i) {
if(i - k >= 0)
suff[i] = suff[i - k];
suff[i] = suff[i] + (l - p[n - i]) * 2;
}
int lastup = n;
for(int i = 0; i <= n; ++i) {
lastup = std::max(lastup, n - i);
while(lastup > 0 && cost(i, lastup - 1, l, k, n) <= cost(i, lastup, l, k, n))
--lastup;
rez = std::min(rez, cost(i, lastup, l, k, n));
}
return rez;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
504 KB |
Output is correct |
5 |
Correct |
12 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
388 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
504 KB |
Output is correct |
5 |
Correct |
12 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
388 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
504 KB |
Output is correct |
5 |
Correct |
12 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
388 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
7 ms |
504 KB |
Output is correct |
5 |
Correct |
12 ms |
376 KB |
Output is correct |
6 |
Correct |
10 ms |
388 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |