#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
template<class T> auto create(T x) { return x; }
template<class... Ts> auto create(int n, Ts... x) {
return vector(n, create(x...));
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, len;
cin >> n >> len;
vector<int> x(n), t(n);
REP(i, n) cin >> x[i];
REP(i, n) cin >> t[i];
auto dp = create(n + 1, n + 1, n + 1, 2, (long long) 1e9 + 1);
vector<int> d(n + 2);
REP(i, n) d[i + 1] = x[i];
d[n + 1] = len;
auto left = [&](int a, int b) { return d[b] - d[a]; };
auto right = [&](int a, int b) { return d[n + 1 - a] - d[n + 1 - b]; };
dp[0][0][0][0] = 0;
dp[0][0][0][1] = 0;
int ans = 0;
REP(l, n + 1) REP(r, n + 1) {
if(l + r > n) break;
REP(k, n + 1) {
if(l) {
dp[l][r][k][0] = min(dp[l][r][k][0], dp[l - 1][r][k][0] + left(l - 1, l));
dp[l][r][k][0] = min(dp[l][r][k][0], dp[l - 1][r][k][1] + left(0, l) + right(0, r));
}
if(r) {
dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r - 1][k][1] + right(r - 1, r));
dp[l][r][k][1] = min(dp[l][r][k][1], dp[l][r - 1][k][0] + left(0, l) + right(0, r));
}
}
for(int k = n; k >= 1; k--) {
if(l && dp[l][r][k - 1][0] <= t[l - 1]) {
dp[l][r][k][0] = dp[l][r][k - 1][0];
ans = max(ans, k);
}
if(r && dp[l][r][k - 1][1] <= t[n - r]) {
dp[l][r][k][1] = dp[l][r][k - 1][1];
ans = max(ans, k);
}
}
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
408 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
408 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
508 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
7 ms |
504 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
504 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
5 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
504 KB |
Output is correct |
30 |
Correct |
5 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
5 ms |
504 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
408 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
508 KB |
Output is correct |
18 |
Correct |
458 ms |
323108 KB |
Output is correct |
19 |
Correct |
223 ms |
152592 KB |
Output is correct |
20 |
Correct |
90 ms |
59512 KB |
Output is correct |
21 |
Correct |
202 ms |
140024 KB |
Output is correct |
22 |
Correct |
297 ms |
206560 KB |
Output is correct |
23 |
Correct |
75 ms |
46712 KB |
Output is correct |
24 |
Correct |
51 ms |
32248 KB |
Output is correct |
25 |
Correct |
68 ms |
45176 KB |
Output is correct |
26 |
Correct |
19 ms |
10744 KB |
Output is correct |
27 |
Correct |
72 ms |
48124 KB |
Output is correct |
28 |
Correct |
51 ms |
29048 KB |
Output is correct |
29 |
Correct |
77 ms |
49656 KB |
Output is correct |
30 |
Correct |
54 ms |
34552 KB |
Output is correct |
31 |
Correct |
71 ms |
45176 KB |
Output is correct |
32 |
Correct |
29 ms |
17272 KB |
Output is correct |
33 |
Correct |
71 ms |
45304 KB |
Output is correct |
34 |
Correct |
18 ms |
9720 KB |
Output is correct |
35 |
Correct |
66 ms |
43768 KB |
Output is correct |
36 |
Correct |
25 ms |
14328 KB |
Output is correct |
37 |
Correct |
71 ms |
48120 KB |
Output is correct |
38 |
Correct |
34 ms |
19576 KB |
Output is correct |
39 |
Correct |
77 ms |
51192 KB |
Output is correct |
40 |
Correct |
37 ms |
23036 KB |
Output is correct |
41 |
Correct |
609 ms |
442616 KB |
Output is correct |
42 |
Correct |
339 ms |
244600 KB |
Output is correct |
43 |
Correct |
624 ms |
442484 KB |
Output is correct |
44 |
Correct |
339 ms |
239864 KB |
Output is correct |
45 |
Correct |
641 ms |
442488 KB |
Output is correct |
46 |
Correct |
345 ms |
244728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
504 KB |
Output is correct |
7 |
Correct |
5 ms |
376 KB |
Output is correct |
8 |
Correct |
5 ms |
408 KB |
Output is correct |
9 |
Correct |
6 ms |
632 KB |
Output is correct |
10 |
Correct |
5 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
5 ms |
504 KB |
Output is correct |
13 |
Correct |
5 ms |
504 KB |
Output is correct |
14 |
Correct |
5 ms |
376 KB |
Output is correct |
15 |
Correct |
5 ms |
376 KB |
Output is correct |
16 |
Correct |
5 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
508 KB |
Output is correct |
18 |
Correct |
5 ms |
504 KB |
Output is correct |
19 |
Correct |
5 ms |
376 KB |
Output is correct |
20 |
Correct |
7 ms |
504 KB |
Output is correct |
21 |
Correct |
5 ms |
504 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
6 ms |
504 KB |
Output is correct |
24 |
Correct |
5 ms |
504 KB |
Output is correct |
25 |
Correct |
5 ms |
504 KB |
Output is correct |
26 |
Correct |
5 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
5 ms |
376 KB |
Output is correct |
29 |
Correct |
5 ms |
504 KB |
Output is correct |
30 |
Correct |
5 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
504 KB |
Output is correct |
32 |
Correct |
5 ms |
504 KB |
Output is correct |
33 |
Correct |
5 ms |
504 KB |
Output is correct |
34 |
Correct |
5 ms |
504 KB |
Output is correct |
35 |
Correct |
5 ms |
504 KB |
Output is correct |
36 |
Correct |
458 ms |
323108 KB |
Output is correct |
37 |
Correct |
223 ms |
152592 KB |
Output is correct |
38 |
Correct |
90 ms |
59512 KB |
Output is correct |
39 |
Correct |
202 ms |
140024 KB |
Output is correct |
40 |
Correct |
297 ms |
206560 KB |
Output is correct |
41 |
Correct |
75 ms |
46712 KB |
Output is correct |
42 |
Correct |
51 ms |
32248 KB |
Output is correct |
43 |
Correct |
68 ms |
45176 KB |
Output is correct |
44 |
Correct |
19 ms |
10744 KB |
Output is correct |
45 |
Correct |
72 ms |
48124 KB |
Output is correct |
46 |
Correct |
51 ms |
29048 KB |
Output is correct |
47 |
Correct |
77 ms |
49656 KB |
Output is correct |
48 |
Correct |
54 ms |
34552 KB |
Output is correct |
49 |
Correct |
71 ms |
45176 KB |
Output is correct |
50 |
Correct |
29 ms |
17272 KB |
Output is correct |
51 |
Correct |
71 ms |
45304 KB |
Output is correct |
52 |
Correct |
18 ms |
9720 KB |
Output is correct |
53 |
Correct |
66 ms |
43768 KB |
Output is correct |
54 |
Correct |
25 ms |
14328 KB |
Output is correct |
55 |
Correct |
71 ms |
48120 KB |
Output is correct |
56 |
Correct |
34 ms |
19576 KB |
Output is correct |
57 |
Correct |
77 ms |
51192 KB |
Output is correct |
58 |
Correct |
37 ms |
23036 KB |
Output is correct |
59 |
Correct |
609 ms |
442616 KB |
Output is correct |
60 |
Correct |
339 ms |
244600 KB |
Output is correct |
61 |
Correct |
624 ms |
442484 KB |
Output is correct |
62 |
Correct |
339 ms |
239864 KB |
Output is correct |
63 |
Correct |
641 ms |
442488 KB |
Output is correct |
64 |
Correct |
345 ms |
244728 KB |
Output is correct |
65 |
Correct |
533 ms |
379640 KB |
Output is correct |
66 |
Correct |
469 ms |
334072 KB |
Output is correct |
67 |
Correct |
449 ms |
312488 KB |
Output is correct |
68 |
Correct |
400 ms |
276856 KB |
Output is correct |
69 |
Correct |
542 ms |
373368 KB |
Output is correct |
70 |
Correct |
504 ms |
350200 KB |
Output is correct |
71 |
Correct |
484 ms |
356216 KB |
Output is correct |
72 |
Correct |
519 ms |
361720 KB |
Output is correct |
73 |
Correct |
458 ms |
322888 KB |
Output is correct |
74 |
Correct |
429 ms |
291832 KB |
Output is correct |
75 |
Correct |
466 ms |
339064 KB |
Output is correct |
76 |
Correct |
579 ms |
416632 KB |
Output is correct |
77 |
Correct |
584 ms |
416760 KB |
Output is correct |
78 |
Correct |
396 ms |
281976 KB |
Output is correct |
79 |
Correct |
427 ms |
296820 KB |
Output is correct |
80 |
Correct |
576 ms |
403908 KB |
Output is correct |
81 |
Correct |
419 ms |
302072 KB |
Output is correct |
82 |
Correct |
468 ms |
328056 KB |
Output is correct |
83 |
Correct |
607 ms |
442696 KB |
Output is correct |
84 |
Correct |
493 ms |
350328 KB |
Output is correct |
85 |
Correct |
548 ms |
397560 KB |
Output is correct |
86 |
Correct |
532 ms |
385400 KB |
Output is correct |
87 |
Correct |
481 ms |
339064 KB |
Output is correct |
88 |
Correct |
630 ms |
448760 KB |
Output is correct |
89 |
Correct |
634 ms |
448760 KB |
Output is correct |
90 |
Correct |
511 ms |
344952 KB |
Output is correct |
91 |
Correct |
628 ms |
448888 KB |
Output is correct |
92 |
Correct |
615 ms |
448760 KB |
Output is correct |
93 |
Correct |
619 ms |
435680 KB |
Output is correct |