#include "boxes.h"
#include "bits/stdc++.h"
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, s, n) for(ll i = ll(s); i < ll(n); ++i)
#define rrep(i, n) for(ll i = ll(n)-1; i >= 0; --i)
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(),a.end()
#define SZ(a) int(a.size())
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vp = vector<P>;
using vvp = vector<vp>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vs = vector<string>;
const int inf = 1001001001;
const ll linf = 1001001001001001001;
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
ll delivery(int n, int k, int l, int p[]) {
vl a, b;
a.pb(0);
rep(i, n) {
if (p[i] <= l / 2) a.pb(p[i]);
else b.pb(l - p[i]);
}
b.pb(0);
reverse(all(b));
rep(i, SZ(a)) {
a[i] *= 2;
if (i >= k) a[i] += a[i - k];
}
rep(i, SZ(b)) {
b[i] *= 2;
if (i >= k) b[i] += b[i - k];
}
ll ans = a.back() + b.back();
ll mx = max(0LL, ans - ll(n + k - 1) / k * l);
for (ll &i: a) i = a.back() - i;
for (ll &i: b) i = b.back() - i;
reverse(all(a));
reverse(all(b));
// rep(i, SZ(a)) rep(j, SZ(b)) {
// if ((i + j) % k) continue;
// chmax(mx, a[i] + b[j] - ll(i + j + k - 1) / k * l);
// }
rep(sa, k + 1) {
int ori = sa;
int sb = k - sa;
if (sa >= SZ(a) or sb >= SZ(b)) continue;
ll now = a[sa] + b[sb] - l;
chmax(mx, now);
while (sa + k < SZ(a) or sb + k < SZ(b)) {
if (sa + k < SZ(a) and sb + k < SZ(b)) {
if (a[sa + k] - a[sa] > b[sb + k] - b[sb]) {
now += a[sa + k] - a[sa] - l;
sa += k;
} else {
now += b[sb + k] - b[sb] - l;
sb += k;
}
} else if (sa + k < SZ(a)) {
now += a[sa + k] - a[sa] - l;
sa += k;
} else {
now += b[sb + k] - b[sb] - l;
sb += k;
}
chmax(mx, now);
}
sa = ori;
}
return ans - mx;
}
Compilation message
boxes.cpp: In function 'll delivery(int, int, int, int*)':
boxes.cpp:71:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
71 | int ori = sa;
| ^~
boxes.cpp:72:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
72 | int sb = k - sa;
| ~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
58 ms |
14244 KB |
Output is correct |
34 |
Correct |
31 ms |
16092 KB |
Output is correct |
35 |
Correct |
29 ms |
16152 KB |
Output is correct |
36 |
Correct |
55 ms |
22224 KB |
Output is correct |
37 |
Correct |
62 ms |
22356 KB |
Output is correct |
38 |
Correct |
66 ms |
23796 KB |
Output is correct |
39 |
Correct |
51 ms |
22560 KB |
Output is correct |
40 |
Correct |
33 ms |
17924 KB |
Output is correct |
41 |
Correct |
57 ms |
22280 KB |
Output is correct |
42 |
Correct |
36 ms |
16364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
58 ms |
14244 KB |
Output is correct |
34 |
Correct |
31 ms |
16092 KB |
Output is correct |
35 |
Correct |
29 ms |
16152 KB |
Output is correct |
36 |
Correct |
55 ms |
22224 KB |
Output is correct |
37 |
Correct |
62 ms |
22356 KB |
Output is correct |
38 |
Correct |
66 ms |
23796 KB |
Output is correct |
39 |
Correct |
51 ms |
22560 KB |
Output is correct |
40 |
Correct |
33 ms |
17924 KB |
Output is correct |
41 |
Correct |
57 ms |
22280 KB |
Output is correct |
42 |
Correct |
36 ms |
16364 KB |
Output is correct |
43 |
Correct |
600 ms |
220060 KB |
Output is correct |
44 |
Correct |
240 ms |
155224 KB |
Output is correct |
45 |
Correct |
289 ms |
173276 KB |
Output is correct |
46 |
Correct |
539 ms |
242948 KB |
Output is correct |
47 |
Correct |
556 ms |
188252 KB |
Output is correct |
48 |
Correct |
546 ms |
239048 KB |
Output is correct |
49 |
Correct |
476 ms |
200656 KB |
Output is correct |
50 |
Correct |
303 ms |
180912 KB |
Output is correct |
51 |
Correct |
572 ms |
239168 KB |
Output is correct |
52 |
Correct |
326 ms |
209888 KB |
Output is correct |