#include "boxes.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <set>
#include <map>
#include <queue>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <functional>
using namespace std;
template<typename T> void uin(T &a, T b) {
if (b < a) {
a = b;
}
}
const int N = 10 * 1000 * 1000 + 7; // for now
const long long INF = 1e18 + 228;
long long pref[N], suff[N];
priority_queue<long long> Q[N / 2];
long long mod[N / 2];
long long delivery(int n, int k, int L, int p[]) {
for (int i = 1; i <= n; ++i) {
pref[i] = 2LL * p[i - 1];
if (i > k) {
pref[i] += pref[i - k];
}
}
for (int i = n; i; --i) {
suff[i] = 2LL * (L - p[i - 1]);
if (i + k <= n) {
suff[i] += suff[i + k];
}
}
/*for (int i = 1; i <= n; ++i) {
cout << pref[i] << ' ';
}
cout << endl;
for (int i = 1; i <= n; ++i) {
cout << suff[i] << ' ';
}
cout << '\n';*/
long long answer = min(suff[1], pref[n]);
if (k < n / 2) {
int rem = 0;
for (int r = 1; r <= n + 1; ++r) {
mod[rem] += L;
Q[rem].push(-(pref[r - 1] - mod[rem]));
uin(answer, suff[r] + (-Q[rem].top() + mod[rem] ));
++rem;
if (rem == k) rem = 0;
}
} else {
for (int c = 0; c <= (n + k - 1) / k; ++c) {
long long cur = (long long)L * (long long)c;
long long addit = INF;
for (int l = 1; l <= n - c * k + 1; ++l) {
uin(addit, pref[l - 1] + suff[l + c * k]);
}
uin(answer, cur + addit);
}
}
return answer;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
156920 KB |
Output is correct |
2 |
Correct |
87 ms |
156920 KB |
Output is correct |
3 |
Correct |
89 ms |
156920 KB |
Output is correct |
4 |
Correct |
96 ms |
156920 KB |
Output is correct |
5 |
Correct |
91 ms |
156920 KB |
Output is correct |
6 |
Correct |
87 ms |
156920 KB |
Output is correct |
7 |
Correct |
95 ms |
156920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
156920 KB |
Output is correct |
2 |
Correct |
85 ms |
156920 KB |
Output is correct |
3 |
Correct |
85 ms |
156920 KB |
Output is correct |
4 |
Correct |
94 ms |
156920 KB |
Output is correct |
5 |
Correct |
86 ms |
156920 KB |
Output is correct |
6 |
Correct |
89 ms |
156920 KB |
Output is correct |
7 |
Correct |
90 ms |
156920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
156920 KB |
Output is correct |
2 |
Correct |
85 ms |
156920 KB |
Output is correct |
3 |
Correct |
87 ms |
156920 KB |
Output is correct |
4 |
Correct |
85 ms |
156920 KB |
Output is correct |
5 |
Correct |
85 ms |
156920 KB |
Output is correct |
6 |
Correct |
86 ms |
156920 KB |
Output is correct |
7 |
Correct |
86 ms |
156920 KB |
Output is correct |
8 |
Correct |
100 ms |
156924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
156920 KB |
Output is correct |
2 |
Correct |
87 ms |
156920 KB |
Output is correct |
3 |
Correct |
89 ms |
156920 KB |
Output is correct |
4 |
Correct |
96 ms |
156920 KB |
Output is correct |
5 |
Correct |
91 ms |
156920 KB |
Output is correct |
6 |
Correct |
87 ms |
156920 KB |
Output is correct |
7 |
Correct |
95 ms |
156920 KB |
Output is correct |
8 |
Correct |
86 ms |
156920 KB |
Output is correct |
9 |
Correct |
85 ms |
156920 KB |
Output is correct |
10 |
Correct |
85 ms |
156920 KB |
Output is correct |
11 |
Correct |
94 ms |
156920 KB |
Output is correct |
12 |
Correct |
86 ms |
156920 KB |
Output is correct |
13 |
Correct |
89 ms |
156920 KB |
Output is correct |
14 |
Correct |
90 ms |
156920 KB |
Output is correct |
15 |
Correct |
86 ms |
156920 KB |
Output is correct |
16 |
Correct |
85 ms |
156920 KB |
Output is correct |
17 |
Correct |
87 ms |
156920 KB |
Output is correct |
18 |
Correct |
85 ms |
156920 KB |
Output is correct |
19 |
Correct |
85 ms |
156920 KB |
Output is correct |
20 |
Correct |
86 ms |
156920 KB |
Output is correct |
21 |
Correct |
86 ms |
156920 KB |
Output is correct |
22 |
Correct |
100 ms |
156924 KB |
Output is correct |
23 |
Correct |
89 ms |
156920 KB |
Output is correct |
24 |
Correct |
87 ms |
156924 KB |
Output is correct |
25 |
Correct |
89 ms |
156920 KB |
Output is correct |
26 |
Correct |
87 ms |
156920 KB |
Output is correct |
27 |
Correct |
91 ms |
156968 KB |
Output is correct |
28 |
Correct |
86 ms |
156920 KB |
Output is correct |
29 |
Correct |
86 ms |
156920 KB |
Output is correct |
30 |
Correct |
86 ms |
156920 KB |
Output is correct |
31 |
Correct |
88 ms |
157048 KB |
Output is correct |
32 |
Correct |
93 ms |
157012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
156920 KB |
Output is correct |
2 |
Correct |
87 ms |
156920 KB |
Output is correct |
3 |
Correct |
89 ms |
156920 KB |
Output is correct |
4 |
Correct |
96 ms |
156920 KB |
Output is correct |
5 |
Correct |
91 ms |
156920 KB |
Output is correct |
6 |
Correct |
87 ms |
156920 KB |
Output is correct |
7 |
Correct |
95 ms |
156920 KB |
Output is correct |
8 |
Correct |
86 ms |
156920 KB |
Output is correct |
9 |
Correct |
85 ms |
156920 KB |
Output is correct |
10 |
Correct |
85 ms |
156920 KB |
Output is correct |
11 |
Correct |
94 ms |
156920 KB |
Output is correct |
12 |
Correct |
86 ms |
156920 KB |
Output is correct |
13 |
Correct |
89 ms |
156920 KB |
Output is correct |
14 |
Correct |
90 ms |
156920 KB |
Output is correct |
15 |
Correct |
86 ms |
156920 KB |
Output is correct |
16 |
Correct |
85 ms |
156920 KB |
Output is correct |
17 |
Correct |
87 ms |
156920 KB |
Output is correct |
18 |
Correct |
85 ms |
156920 KB |
Output is correct |
19 |
Correct |
85 ms |
156920 KB |
Output is correct |
20 |
Correct |
86 ms |
156920 KB |
Output is correct |
21 |
Correct |
86 ms |
156920 KB |
Output is correct |
22 |
Correct |
100 ms |
156924 KB |
Output is correct |
23 |
Correct |
89 ms |
156920 KB |
Output is correct |
24 |
Correct |
87 ms |
156924 KB |
Output is correct |
25 |
Correct |
89 ms |
156920 KB |
Output is correct |
26 |
Correct |
87 ms |
156920 KB |
Output is correct |
27 |
Correct |
91 ms |
156968 KB |
Output is correct |
28 |
Correct |
86 ms |
156920 KB |
Output is correct |
29 |
Correct |
86 ms |
156920 KB |
Output is correct |
30 |
Correct |
86 ms |
156920 KB |
Output is correct |
31 |
Correct |
88 ms |
157048 KB |
Output is correct |
32 |
Correct |
93 ms |
157012 KB |
Output is correct |
33 |
Correct |
169 ms |
188576 KB |
Output is correct |
34 |
Correct |
145 ms |
188612 KB |
Output is correct |
35 |
Correct |
136 ms |
184688 KB |
Output is correct |
36 |
Correct |
165 ms |
188536 KB |
Output is correct |
37 |
Correct |
166 ms |
186104 KB |
Output is correct |
38 |
Correct |
172 ms |
186104 KB |
Output is correct |
39 |
Correct |
158 ms |
188536 KB |
Output is correct |
40 |
Correct |
152 ms |
188640 KB |
Output is correct |
41 |
Correct |
163 ms |
189560 KB |
Output is correct |
42 |
Correct |
149 ms |
186232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
156920 KB |
Output is correct |
2 |
Correct |
87 ms |
156920 KB |
Output is correct |
3 |
Correct |
89 ms |
156920 KB |
Output is correct |
4 |
Correct |
96 ms |
156920 KB |
Output is correct |
5 |
Correct |
91 ms |
156920 KB |
Output is correct |
6 |
Correct |
87 ms |
156920 KB |
Output is correct |
7 |
Correct |
95 ms |
156920 KB |
Output is correct |
8 |
Correct |
86 ms |
156920 KB |
Output is correct |
9 |
Correct |
85 ms |
156920 KB |
Output is correct |
10 |
Correct |
85 ms |
156920 KB |
Output is correct |
11 |
Correct |
94 ms |
156920 KB |
Output is correct |
12 |
Correct |
86 ms |
156920 KB |
Output is correct |
13 |
Correct |
89 ms |
156920 KB |
Output is correct |
14 |
Correct |
90 ms |
156920 KB |
Output is correct |
15 |
Correct |
86 ms |
156920 KB |
Output is correct |
16 |
Correct |
85 ms |
156920 KB |
Output is correct |
17 |
Correct |
87 ms |
156920 KB |
Output is correct |
18 |
Correct |
85 ms |
156920 KB |
Output is correct |
19 |
Correct |
85 ms |
156920 KB |
Output is correct |
20 |
Correct |
86 ms |
156920 KB |
Output is correct |
21 |
Correct |
86 ms |
156920 KB |
Output is correct |
22 |
Correct |
100 ms |
156924 KB |
Output is correct |
23 |
Correct |
89 ms |
156920 KB |
Output is correct |
24 |
Correct |
87 ms |
156924 KB |
Output is correct |
25 |
Correct |
89 ms |
156920 KB |
Output is correct |
26 |
Correct |
87 ms |
156920 KB |
Output is correct |
27 |
Correct |
91 ms |
156968 KB |
Output is correct |
28 |
Correct |
86 ms |
156920 KB |
Output is correct |
29 |
Correct |
86 ms |
156920 KB |
Output is correct |
30 |
Correct |
86 ms |
156920 KB |
Output is correct |
31 |
Correct |
88 ms |
157048 KB |
Output is correct |
32 |
Correct |
93 ms |
157012 KB |
Output is correct |
33 |
Correct |
169 ms |
188576 KB |
Output is correct |
34 |
Correct |
145 ms |
188612 KB |
Output is correct |
35 |
Correct |
136 ms |
184688 KB |
Output is correct |
36 |
Correct |
165 ms |
188536 KB |
Output is correct |
37 |
Correct |
166 ms |
186104 KB |
Output is correct |
38 |
Correct |
172 ms |
186104 KB |
Output is correct |
39 |
Correct |
158 ms |
188536 KB |
Output is correct |
40 |
Correct |
152 ms |
188640 KB |
Output is correct |
41 |
Correct |
163 ms |
189560 KB |
Output is correct |
42 |
Correct |
149 ms |
186232 KB |
Output is correct |
43 |
Correct |
1063 ms |
501348 KB |
Output is correct |
44 |
Correct |
676 ms |
493948 KB |
Output is correct |
45 |
Correct |
686 ms |
445528 KB |
Output is correct |
46 |
Correct |
1056 ms |
494520 KB |
Output is correct |
47 |
Correct |
1047 ms |
459492 KB |
Output is correct |
48 |
Correct |
954 ms |
461820 KB |
Output is correct |
49 |
Correct |
968 ms |
502068 KB |
Output is correct |
50 |
Correct |
764 ms |
506400 KB |
Output is correct |
51 |
Correct |
1051 ms |
512664 KB |
Output is correct |
52 |
Correct |
711 ms |
466144 KB |
Output is correct |