#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define ff first
#define sc second
#define pb push_back
#define int ll
int dp[210][210][210][2];
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int n, l; cin >> n >> l;
vector<int> x(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> x[i];
vector<int> t(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> t[i];
auto getd = [&](int i, int j) {
return min(abs(x[i] - x[j]), l - abs(x[i] - x[j]));
};
for (int i = 0; i <= 200; i++) {
for (int j = 0; j <= 200;j++) {
for (int cnt = 0; cnt <= 200; cnt++) {
for (int I = 0; I < 2; I++) dp[i][j][cnt][I] = 1e15;
}
}
}
dp[1][0][1][0] = 0;
dp[1][0][1][1] = 0;
for (int cnt = 2; cnt <= n + 1; cnt++) {
for (int left = 1; left <= cnt; left++) {
int right = cnt - left;
for (int C = 1; C <= cnt; C++) {
auto relax = [&](int side, int val) {
if (val < 1e15) {
dp[left][right][C][side] = min(dp[left][right][C][side], val);
}
};
{
int prev_left = (left == 1 ? n : left - 2);
int prev_right = (right == 0 ? 0 : n - right + 1);
if (dp[left - 1][right][C - 1][0] + getd(prev_left, left - 1) <= t[left - 1]) {
relax(0, dp[left - 1][right][C - 1][0] + getd(prev_left, left - 1));
}
if (dp[left - 1][right][C][0] + getd(prev_left, left - 1) > t[left - 1]) {
relax(0, dp[left - 1][right][C][0] + getd(prev_left, left - 1));
}
if (dp[left - 1][right][C - 1][1] + getd(prev_right, left - 1) <= t[left - 1]) {
relax(0, dp[left - 1][right][C - 1][1] + getd(prev_right, left - 1));
}
if (dp[left - 1][right][C][1] + getd(prev_right, left - 1) > t[left - 1]) {
relax(0, dp[left - 1][right][C][1] + getd(prev_right, left - 1));
}
}
if (right) {
int prev_left = left - 1, prev_right = (right == 1 ? 0 : n - (right - 1) + 1);
int cur = n - right + 1;
if (dp[left][right - 1][C - 1][0] + getd(prev_left, cur) <= t[cur]) {
relax(1, dp[left][right - 1][C - 1][0] + getd(prev_left, cur));
}
if (dp[left][right - 1][C][0] + getd(prev_left, cur) > t[cur]) {
relax(1, dp[left][right - 1][C][0] + getd(prev_left, cur));
}
if (dp[left][right - 1][C - 1][1] + getd(prev_right, cur) <= t[cur]) {
relax(1, dp[left][right - 1][C - 1][1] + getd(prev_right, cur));
}
if (dp[left][right - 1][C][1] + getd(prev_right, cur) > t[cur]) {
relax(1, dp[left][right - 1][C][1] + getd(prev_right, cur));
}
}
}
}
}
int ans = 0;
for (int left = 1; left <= n + 1; left++) {
for (int cnt = 1; cnt <= n + 1; cnt++) {
if (dp[left][n + 1 - left][cnt][0] < 1e15 || dp[left][n + 1 - left][cnt][1] < 1e15) ans = max(ans, cnt);
}
}
cout << ans - 1 << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
135252 KB |
Output is correct |
2 |
Correct |
37 ms |
135248 KB |
Output is correct |
3 |
Correct |
40 ms |
135236 KB |
Output is correct |
4 |
Correct |
38 ms |
135260 KB |
Output is correct |
5 |
Correct |
38 ms |
135248 KB |
Output is correct |
6 |
Correct |
37 ms |
135248 KB |
Output is correct |
7 |
Correct |
37 ms |
135252 KB |
Output is correct |
8 |
Correct |
41 ms |
134996 KB |
Output is correct |
9 |
Correct |
38 ms |
135248 KB |
Output is correct |
10 |
Correct |
36 ms |
135248 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
53 ms |
135252 KB |
Output is correct |
13 |
Correct |
41 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135252 KB |
Output is correct |
15 |
Correct |
38 ms |
135248 KB |
Output is correct |
16 |
Correct |
42 ms |
135136 KB |
Output is correct |
17 |
Correct |
38 ms |
135260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
135252 KB |
Output is correct |
2 |
Correct |
37 ms |
135248 KB |
Output is correct |
3 |
Correct |
40 ms |
135236 KB |
Output is correct |
4 |
Correct |
38 ms |
135260 KB |
Output is correct |
5 |
Correct |
38 ms |
135248 KB |
Output is correct |
6 |
Correct |
37 ms |
135248 KB |
Output is correct |
7 |
Correct |
37 ms |
135252 KB |
Output is correct |
8 |
Correct |
41 ms |
134996 KB |
Output is correct |
9 |
Correct |
38 ms |
135248 KB |
Output is correct |
10 |
Correct |
36 ms |
135248 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
53 ms |
135252 KB |
Output is correct |
13 |
Correct |
41 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135252 KB |
Output is correct |
15 |
Correct |
38 ms |
135248 KB |
Output is correct |
16 |
Correct |
42 ms |
135136 KB |
Output is correct |
17 |
Correct |
38 ms |
135260 KB |
Output is correct |
18 |
Correct |
38 ms |
135260 KB |
Output is correct |
19 |
Correct |
40 ms |
135252 KB |
Output is correct |
20 |
Correct |
38 ms |
135252 KB |
Output is correct |
21 |
Correct |
39 ms |
135256 KB |
Output is correct |
22 |
Correct |
43 ms |
135124 KB |
Output is correct |
23 |
Correct |
36 ms |
135064 KB |
Output is correct |
24 |
Correct |
38 ms |
135208 KB |
Output is correct |
25 |
Correct |
39 ms |
134996 KB |
Output is correct |
26 |
Correct |
39 ms |
135252 KB |
Output is correct |
27 |
Correct |
38 ms |
135052 KB |
Output is correct |
28 |
Correct |
40 ms |
135068 KB |
Output is correct |
29 |
Correct |
38 ms |
135084 KB |
Output is correct |
30 |
Correct |
37 ms |
135248 KB |
Output is correct |
31 |
Correct |
40 ms |
135248 KB |
Output is correct |
32 |
Correct |
39 ms |
135056 KB |
Output is correct |
33 |
Correct |
38 ms |
134992 KB |
Output is correct |
34 |
Correct |
37 ms |
135252 KB |
Output is correct |
35 |
Correct |
38 ms |
135252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
135252 KB |
Output is correct |
2 |
Correct |
37 ms |
135248 KB |
Output is correct |
3 |
Correct |
40 ms |
135236 KB |
Output is correct |
4 |
Correct |
38 ms |
135260 KB |
Output is correct |
5 |
Correct |
38 ms |
135248 KB |
Output is correct |
6 |
Correct |
37 ms |
135248 KB |
Output is correct |
7 |
Correct |
37 ms |
135252 KB |
Output is correct |
8 |
Correct |
41 ms |
134996 KB |
Output is correct |
9 |
Correct |
38 ms |
135248 KB |
Output is correct |
10 |
Correct |
36 ms |
135248 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
53 ms |
135252 KB |
Output is correct |
13 |
Correct |
41 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135252 KB |
Output is correct |
15 |
Correct |
38 ms |
135248 KB |
Output is correct |
16 |
Correct |
42 ms |
135136 KB |
Output is correct |
17 |
Correct |
38 ms |
135260 KB |
Output is correct |
18 |
Correct |
56 ms |
135248 KB |
Output is correct |
19 |
Correct |
50 ms |
135244 KB |
Output is correct |
20 |
Correct |
41 ms |
135252 KB |
Output is correct |
21 |
Correct |
48 ms |
135252 KB |
Output is correct |
22 |
Correct |
53 ms |
135248 KB |
Output is correct |
23 |
Correct |
42 ms |
135248 KB |
Output is correct |
24 |
Correct |
41 ms |
135000 KB |
Output is correct |
25 |
Correct |
42 ms |
135228 KB |
Output is correct |
26 |
Correct |
41 ms |
135120 KB |
Output is correct |
27 |
Correct |
40 ms |
135252 KB |
Output is correct |
28 |
Correct |
41 ms |
135252 KB |
Output is correct |
29 |
Correct |
43 ms |
135220 KB |
Output is correct |
30 |
Correct |
40 ms |
135256 KB |
Output is correct |
31 |
Correct |
44 ms |
135248 KB |
Output is correct |
32 |
Correct |
42 ms |
135260 KB |
Output is correct |
33 |
Correct |
43 ms |
135248 KB |
Output is correct |
34 |
Correct |
38 ms |
135248 KB |
Output is correct |
35 |
Correct |
43 ms |
135176 KB |
Output is correct |
36 |
Correct |
40 ms |
135160 KB |
Output is correct |
37 |
Correct |
44 ms |
135048 KB |
Output is correct |
38 |
Correct |
42 ms |
135248 KB |
Output is correct |
39 |
Correct |
42 ms |
135088 KB |
Output is correct |
40 |
Correct |
41 ms |
135100 KB |
Output is correct |
41 |
Correct |
62 ms |
135336 KB |
Output is correct |
42 |
Correct |
51 ms |
135252 KB |
Output is correct |
43 |
Correct |
62 ms |
135256 KB |
Output is correct |
44 |
Correct |
50 ms |
135052 KB |
Output is correct |
45 |
Correct |
62 ms |
135260 KB |
Output is correct |
46 |
Correct |
51 ms |
135132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
135252 KB |
Output is correct |
2 |
Correct |
37 ms |
135248 KB |
Output is correct |
3 |
Correct |
40 ms |
135236 KB |
Output is correct |
4 |
Correct |
38 ms |
135260 KB |
Output is correct |
5 |
Correct |
38 ms |
135248 KB |
Output is correct |
6 |
Correct |
37 ms |
135248 KB |
Output is correct |
7 |
Correct |
37 ms |
135252 KB |
Output is correct |
8 |
Correct |
41 ms |
134996 KB |
Output is correct |
9 |
Correct |
38 ms |
135248 KB |
Output is correct |
10 |
Correct |
36 ms |
135248 KB |
Output is correct |
11 |
Correct |
40 ms |
135248 KB |
Output is correct |
12 |
Correct |
53 ms |
135252 KB |
Output is correct |
13 |
Correct |
41 ms |
135248 KB |
Output is correct |
14 |
Correct |
39 ms |
135252 KB |
Output is correct |
15 |
Correct |
38 ms |
135248 KB |
Output is correct |
16 |
Correct |
42 ms |
135136 KB |
Output is correct |
17 |
Correct |
38 ms |
135260 KB |
Output is correct |
18 |
Correct |
38 ms |
135260 KB |
Output is correct |
19 |
Correct |
40 ms |
135252 KB |
Output is correct |
20 |
Correct |
38 ms |
135252 KB |
Output is correct |
21 |
Correct |
39 ms |
135256 KB |
Output is correct |
22 |
Correct |
43 ms |
135124 KB |
Output is correct |
23 |
Correct |
36 ms |
135064 KB |
Output is correct |
24 |
Correct |
38 ms |
135208 KB |
Output is correct |
25 |
Correct |
39 ms |
134996 KB |
Output is correct |
26 |
Correct |
39 ms |
135252 KB |
Output is correct |
27 |
Correct |
38 ms |
135052 KB |
Output is correct |
28 |
Correct |
40 ms |
135068 KB |
Output is correct |
29 |
Correct |
38 ms |
135084 KB |
Output is correct |
30 |
Correct |
37 ms |
135248 KB |
Output is correct |
31 |
Correct |
40 ms |
135248 KB |
Output is correct |
32 |
Correct |
39 ms |
135056 KB |
Output is correct |
33 |
Correct |
38 ms |
134992 KB |
Output is correct |
34 |
Correct |
37 ms |
135252 KB |
Output is correct |
35 |
Correct |
38 ms |
135252 KB |
Output is correct |
36 |
Correct |
56 ms |
135248 KB |
Output is correct |
37 |
Correct |
50 ms |
135244 KB |
Output is correct |
38 |
Correct |
41 ms |
135252 KB |
Output is correct |
39 |
Correct |
48 ms |
135252 KB |
Output is correct |
40 |
Correct |
53 ms |
135248 KB |
Output is correct |
41 |
Correct |
42 ms |
135248 KB |
Output is correct |
42 |
Correct |
41 ms |
135000 KB |
Output is correct |
43 |
Correct |
42 ms |
135228 KB |
Output is correct |
44 |
Correct |
41 ms |
135120 KB |
Output is correct |
45 |
Correct |
40 ms |
135252 KB |
Output is correct |
46 |
Correct |
41 ms |
135252 KB |
Output is correct |
47 |
Correct |
43 ms |
135220 KB |
Output is correct |
48 |
Correct |
40 ms |
135256 KB |
Output is correct |
49 |
Correct |
44 ms |
135248 KB |
Output is correct |
50 |
Correct |
42 ms |
135260 KB |
Output is correct |
51 |
Correct |
43 ms |
135248 KB |
Output is correct |
52 |
Correct |
38 ms |
135248 KB |
Output is correct |
53 |
Correct |
43 ms |
135176 KB |
Output is correct |
54 |
Correct |
40 ms |
135160 KB |
Output is correct |
55 |
Correct |
44 ms |
135048 KB |
Output is correct |
56 |
Correct |
42 ms |
135248 KB |
Output is correct |
57 |
Correct |
42 ms |
135088 KB |
Output is correct |
58 |
Correct |
41 ms |
135100 KB |
Output is correct |
59 |
Correct |
62 ms |
135336 KB |
Output is correct |
60 |
Correct |
51 ms |
135252 KB |
Output is correct |
61 |
Correct |
62 ms |
135256 KB |
Output is correct |
62 |
Correct |
50 ms |
135052 KB |
Output is correct |
63 |
Correct |
62 ms |
135260 KB |
Output is correct |
64 |
Correct |
51 ms |
135132 KB |
Output is correct |
65 |
Correct |
63 ms |
135156 KB |
Output is correct |
66 |
Correct |
63 ms |
135252 KB |
Output is correct |
67 |
Correct |
65 ms |
135248 KB |
Output is correct |
68 |
Correct |
58 ms |
135260 KB |
Output is correct |
69 |
Correct |
61 ms |
135048 KB |
Output is correct |
70 |
Correct |
62 ms |
135252 KB |
Output is correct |
71 |
Correct |
59 ms |
135252 KB |
Output is correct |
72 |
Correct |
61 ms |
135032 KB |
Output is correct |
73 |
Correct |
57 ms |
135248 KB |
Output is correct |
74 |
Correct |
56 ms |
135256 KB |
Output is correct |
75 |
Correct |
58 ms |
135196 KB |
Output is correct |
76 |
Correct |
69 ms |
135260 KB |
Output is correct |
77 |
Correct |
66 ms |
135252 KB |
Output is correct |
78 |
Correct |
63 ms |
135252 KB |
Output is correct |
79 |
Correct |
58 ms |
135248 KB |
Output is correct |
80 |
Correct |
67 ms |
135208 KB |
Output is correct |
81 |
Correct |
59 ms |
135248 KB |
Output is correct |
82 |
Correct |
65 ms |
135248 KB |
Output is correct |
83 |
Correct |
64 ms |
135108 KB |
Output is correct |
84 |
Correct |
62 ms |
135260 KB |
Output is correct |
85 |
Correct |
64 ms |
135024 KB |
Output is correct |
86 |
Correct |
65 ms |
135248 KB |
Output is correct |
87 |
Correct |
66 ms |
135248 KB |
Output is correct |
88 |
Correct |
72 ms |
135248 KB |
Output is correct |
89 |
Incorrect |
68 ms |
135248 KB |
Output isn't correct |
90 |
Halted |
0 ms |
0 KB |
- |