#include <bits/stdc++.h>
using namespace std;
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...)
#endif
long long delivery(int n, int k, int l, int p[]) {
vector<long long> dp1(n);
deque<pair<long long, int>> deq;
deq.emplace_front(0, -1);
for (int i = 0; i < n; i++) {
if (deq.front().second < i - k) {
deq.pop_front();
}
dp1[i] = deq.front().first + min(l, p[i] * 2);
while (!deq.empty() && deq.back().first >= dp1[i]) {
deq.pop_back();
}
deq.emplace_back(dp1[i], i);
}
deq.clear();
vector<long long> dp2(n);
deq.emplace_front(0, n);
for (int i = n - 1; i >= 0; i--) {
if (deq.front().second > i + k) {
deq.pop_front();
}
dp2[i] = deq.front().first + min(l, (l - p[i]) * 2);
while (!deq.empty() && deq.back().first >= dp2[i]) {
deq.pop_back();
}
deq.emplace_back(dp2[i], i);
}
long long res = min(dp1[n - 1], dp2[0]);
for (int i = 0; i < n - 1; i++) {
res = min(res, dp1[i] + dp2[i + 1]);
}
return res;
}
#ifdef tabr
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k, l, p[100];
cin >> n >> k >> l;
for (int i = 0; i < n; i++) {
cin >> p[i];
}
cout << delivery(n, k, l, p) << '\n';
return 0;
}
#endif
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
300 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
288 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
292 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
296 KB |
Output is correct |
25 |
Correct |
1 ms |
288 KB |
Output is correct |
26 |
Correct |
0 ms |
296 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
296 KB |
Output is correct |
25 |
Correct |
1 ms |
288 KB |
Output is correct |
26 |
Correct |
0 ms |
296 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
73 ms |
22816 KB |
Output is correct |
34 |
Correct |
39 ms |
21696 KB |
Output is correct |
35 |
Correct |
40 ms |
21748 KB |
Output is correct |
36 |
Correct |
69 ms |
22816 KB |
Output is correct |
37 |
Correct |
71 ms |
22816 KB |
Output is correct |
38 |
Correct |
70 ms |
22860 KB |
Output is correct |
39 |
Correct |
59 ms |
21768 KB |
Output is correct |
40 |
Correct |
50 ms |
21768 KB |
Output is correct |
41 |
Correct |
66 ms |
22888 KB |
Output is correct |
42 |
Correct |
45 ms |
21768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
292 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
0 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
204 KB |
Output is correct |
15 |
Correct |
0 ms |
288 KB |
Output is correct |
16 |
Correct |
0 ms |
204 KB |
Output is correct |
17 |
Correct |
0 ms |
292 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
0 ms |
204 KB |
Output is correct |
20 |
Correct |
1 ms |
204 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
0 ms |
204 KB |
Output is correct |
23 |
Correct |
1 ms |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
296 KB |
Output is correct |
25 |
Correct |
1 ms |
288 KB |
Output is correct |
26 |
Correct |
0 ms |
296 KB |
Output is correct |
27 |
Correct |
0 ms |
204 KB |
Output is correct |
28 |
Correct |
0 ms |
204 KB |
Output is correct |
29 |
Correct |
1 ms |
296 KB |
Output is correct |
30 |
Correct |
0 ms |
204 KB |
Output is correct |
31 |
Correct |
0 ms |
204 KB |
Output is correct |
32 |
Correct |
0 ms |
204 KB |
Output is correct |
33 |
Correct |
73 ms |
22816 KB |
Output is correct |
34 |
Correct |
39 ms |
21696 KB |
Output is correct |
35 |
Correct |
40 ms |
21748 KB |
Output is correct |
36 |
Correct |
69 ms |
22816 KB |
Output is correct |
37 |
Correct |
71 ms |
22816 KB |
Output is correct |
38 |
Correct |
70 ms |
22860 KB |
Output is correct |
39 |
Correct |
59 ms |
21768 KB |
Output is correct |
40 |
Correct |
50 ms |
21768 KB |
Output is correct |
41 |
Correct |
66 ms |
22888 KB |
Output is correct |
42 |
Correct |
45 ms |
21768 KB |
Output is correct |
43 |
Correct |
631 ms |
213920 KB |
Output is correct |
44 |
Correct |
384 ms |
197672 KB |
Output is correct |
45 |
Correct |
390 ms |
201140 KB |
Output is correct |
46 |
Correct |
598 ms |
196452 KB |
Output is correct |
47 |
Correct |
604 ms |
197700 KB |
Output is correct |
48 |
Correct |
609 ms |
197432 KB |
Output is correct |
49 |
Correct |
675 ms |
210760 KB |
Output is correct |
50 |
Correct |
431 ms |
198300 KB |
Output is correct |
51 |
Correct |
640 ms |
203412 KB |
Output is correct |
52 |
Correct |
408 ms |
198836 KB |
Output is correct |