#include <bits/stdc++.h>
using namespace std;
const int N = 212, MOD = 1e9 + 7;
typedef long long ll;
#define int ll
int n,L,t[N],x[N];
ll dp[N][N][N][2];
void test() {
cin >> n >> L;
for(int i = 1;i <= n;i++){
cin >> x[i];
}
for(int i = 1;i <= n;i++){
cin >> t[i];
}
for(int i = 0;i <= n;i++){
for(int j = 0;j <= n;j++){
for(int k = 0;k <= n;k++){
for(int f = 0;f < 2;++f){
dp[i][j][k][f] = 1e18;
}
}
}
}
x[n + 1] = L;
dp[0][0][0][0] = dp[0][0][0][1] = 0;
for(int i = 0;i <= n;i++){
for(int j = 0;j <= n;j++){
if(i + j >= n) break;
for(int k = 0;k <= i + j;k++){
int t1,t2,t3,t4;
t1 = min(dp[i][j][k][1] + x[i + 1] + L - x[n - j + 1], dp[i][j][k][0] + x[i + 1] - x[i]);//i + 1,j,0
t2 = t1 + x[i + 1] + L - x[n - j + 1];//i + 1,j,1
t3 = min(dp[i][j][k][0] + x[i] + L - x[n - j], dp[i][j][k][1] - x[n - j] + x[n - j + 1]);//i,j + 1,1
t4 = t3 + x[i] + L - x[n - j];//i,j + 1,0
{
dp[i + 1][j][k][0] = min(dp[i + 1][j][k][0],t1);
if(t[i + 1] >= t1){
dp[i + 1][j][k + 1][0] = min(dp[i + 1][j][k + 1][0],t1);
}
}
{
dp[i + 1][j][k][1] = min(dp[i + 1][j][k][1],t2);
}
{
dp[i][j + 1][k][1] = min(dp[i][j + 1][k][1],t3);
if(t[n - j] >= t3){
dp[i][j + 1][k + 1][1] = min(dp[i][j + 1][k + 1][1],t3);
}
}
{
dp[i][j + 1][k][0] = min(dp[i][j + 1][k][0],t4);
}
}
}
}
int res = 0;
for(int i = 0;i <= n;i++){
for(int j = 0;j <= n;++j){
if(i + j > n) break;
for(int k = 0;k <= i + j;k++){
if(min(dp[i][j][k][0],dp[i][j][k][1]) != 1e18){
res = max(res,k);
}
}
}
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
test();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8696 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
1 ms |
10588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8696 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
1 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
8536 KB |
Output is correct |
23 |
Correct |
2 ms |
12632 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
1 ms |
10768 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
10584 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
2 ms |
12888 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8696 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
1 ms |
10588 KB |
Output is correct |
18 |
Correct |
52 ms |
127828 KB |
Output is correct |
19 |
Correct |
26 ms |
98904 KB |
Output is correct |
20 |
Correct |
14 ms |
72284 KB |
Output is correct |
21 |
Correct |
25 ms |
96860 KB |
Output is correct |
22 |
Correct |
32 ms |
109148 KB |
Output is correct |
23 |
Correct |
13 ms |
66220 KB |
Output is correct |
24 |
Correct |
11 ms |
60116 KB |
Output is correct |
25 |
Correct |
12 ms |
66136 KB |
Output is correct |
26 |
Correct |
6 ms |
41564 KB |
Output is correct |
27 |
Correct |
14 ms |
68232 KB |
Output is correct |
28 |
Correct |
10 ms |
57948 KB |
Output is correct |
29 |
Correct |
12 ms |
68188 KB |
Output is correct |
30 |
Correct |
11 ms |
59996 KB |
Output is correct |
31 |
Correct |
12 ms |
66136 KB |
Output is correct |
32 |
Correct |
7 ms |
47708 KB |
Output is correct |
33 |
Correct |
15 ms |
66136 KB |
Output is correct |
34 |
Correct |
6 ms |
39516 KB |
Output is correct |
35 |
Correct |
12 ms |
66236 KB |
Output is correct |
36 |
Correct |
7 ms |
45660 KB |
Output is correct |
37 |
Correct |
13 ms |
68292 KB |
Output is correct |
38 |
Correct |
8 ms |
49756 KB |
Output is correct |
39 |
Correct |
13 ms |
68188 KB |
Output is correct |
40 |
Correct |
9 ms |
53852 KB |
Output is correct |
41 |
Correct |
53 ms |
142208 KB |
Output is correct |
42 |
Correct |
34 ms |
117596 KB |
Output is correct |
43 |
Correct |
54 ms |
142172 KB |
Output is correct |
44 |
Correct |
35 ms |
115548 KB |
Output is correct |
45 |
Correct |
50 ms |
142164 KB |
Output is correct |
46 |
Correct |
35 ms |
117592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
10588 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
2 ms |
8696 KB |
Output is correct |
9 |
Correct |
2 ms |
10588 KB |
Output is correct |
10 |
Correct |
0 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2652 KB |
Output is correct |
12 |
Correct |
2 ms |
10588 KB |
Output is correct |
13 |
Correct |
2 ms |
10588 KB |
Output is correct |
14 |
Correct |
1 ms |
6492 KB |
Output is correct |
15 |
Correct |
1 ms |
6488 KB |
Output is correct |
16 |
Correct |
2 ms |
10588 KB |
Output is correct |
17 |
Correct |
1 ms |
10588 KB |
Output is correct |
18 |
Correct |
2 ms |
10588 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
10588 KB |
Output is correct |
21 |
Correct |
2 ms |
10588 KB |
Output is correct |
22 |
Correct |
1 ms |
8536 KB |
Output is correct |
23 |
Correct |
2 ms |
12632 KB |
Output is correct |
24 |
Correct |
2 ms |
10588 KB |
Output is correct |
25 |
Correct |
2 ms |
10588 KB |
Output is correct |
26 |
Correct |
1 ms |
10768 KB |
Output is correct |
27 |
Correct |
1 ms |
6488 KB |
Output is correct |
28 |
Correct |
1 ms |
8540 KB |
Output is correct |
29 |
Correct |
2 ms |
12636 KB |
Output is correct |
30 |
Correct |
2 ms |
12636 KB |
Output is correct |
31 |
Correct |
2 ms |
10584 KB |
Output is correct |
32 |
Correct |
2 ms |
10588 KB |
Output is correct |
33 |
Correct |
2 ms |
12636 KB |
Output is correct |
34 |
Correct |
2 ms |
12888 KB |
Output is correct |
35 |
Correct |
2 ms |
12636 KB |
Output is correct |
36 |
Correct |
52 ms |
127828 KB |
Output is correct |
37 |
Correct |
26 ms |
98904 KB |
Output is correct |
38 |
Correct |
14 ms |
72284 KB |
Output is correct |
39 |
Correct |
25 ms |
96860 KB |
Output is correct |
40 |
Correct |
32 ms |
109148 KB |
Output is correct |
41 |
Correct |
13 ms |
66220 KB |
Output is correct |
42 |
Correct |
11 ms |
60116 KB |
Output is correct |
43 |
Correct |
12 ms |
66136 KB |
Output is correct |
44 |
Correct |
6 ms |
41564 KB |
Output is correct |
45 |
Correct |
14 ms |
68232 KB |
Output is correct |
46 |
Correct |
10 ms |
57948 KB |
Output is correct |
47 |
Correct |
12 ms |
68188 KB |
Output is correct |
48 |
Correct |
11 ms |
59996 KB |
Output is correct |
49 |
Correct |
12 ms |
66136 KB |
Output is correct |
50 |
Correct |
7 ms |
47708 KB |
Output is correct |
51 |
Correct |
15 ms |
66136 KB |
Output is correct |
52 |
Correct |
6 ms |
39516 KB |
Output is correct |
53 |
Correct |
12 ms |
66236 KB |
Output is correct |
54 |
Correct |
7 ms |
45660 KB |
Output is correct |
55 |
Correct |
13 ms |
68292 KB |
Output is correct |
56 |
Correct |
8 ms |
49756 KB |
Output is correct |
57 |
Correct |
13 ms |
68188 KB |
Output is correct |
58 |
Correct |
9 ms |
53852 KB |
Output is correct |
59 |
Correct |
53 ms |
142208 KB |
Output is correct |
60 |
Correct |
34 ms |
117596 KB |
Output is correct |
61 |
Correct |
54 ms |
142172 KB |
Output is correct |
62 |
Correct |
35 ms |
115548 KB |
Output is correct |
63 |
Correct |
50 ms |
142164 KB |
Output is correct |
64 |
Correct |
35 ms |
117592 KB |
Output is correct |
65 |
Correct |
45 ms |
136024 KB |
Output is correct |
66 |
Correct |
46 ms |
129792 KB |
Output is correct |
67 |
Correct |
40 ms |
125788 KB |
Output is correct |
68 |
Correct |
39 ms |
121692 KB |
Output is correct |
69 |
Correct |
46 ms |
133972 KB |
Output is correct |
70 |
Correct |
44 ms |
131920 KB |
Output is correct |
71 |
Correct |
46 ms |
131952 KB |
Output is correct |
72 |
Correct |
46 ms |
131932 KB |
Output is correct |
73 |
Correct |
41 ms |
127832 KB |
Output is correct |
74 |
Correct |
41 ms |
123740 KB |
Output is correct |
75 |
Correct |
44 ms |
129884 KB |
Output is correct |
76 |
Correct |
49 ms |
140120 KB |
Output is correct |
77 |
Correct |
48 ms |
140116 KB |
Output is correct |
78 |
Correct |
43 ms |
121708 KB |
Output is correct |
79 |
Correct |
41 ms |
123740 KB |
Output is correct |
80 |
Correct |
49 ms |
137976 KB |
Output is correct |
81 |
Correct |
41 ms |
125784 KB |
Output is correct |
82 |
Correct |
43 ms |
127836 KB |
Output is correct |
83 |
Correct |
51 ms |
140892 KB |
Output is correct |
84 |
Correct |
45 ms |
132176 KB |
Output is correct |
85 |
Correct |
47 ms |
138072 KB |
Output is correct |
86 |
Correct |
46 ms |
136024 KB |
Output is correct |
87 |
Correct |
43 ms |
129884 KB |
Output is correct |
88 |
Correct |
52 ms |
142124 KB |
Output is correct |
89 |
Correct |
50 ms |
142168 KB |
Output is correct |
90 |
Correct |
43 ms |
129884 KB |
Output is correct |
91 |
Correct |
51 ms |
142160 KB |
Output is correct |
92 |
Correct |
51 ms |
142212 KB |
Output is correct |
93 |
Correct |
49 ms |
142168 KB |
Output is correct |