#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN=205;
const int INF=1e9+5;
int n,L;
int x[MAXN];
int t[MAXN];
int dp[MAXN][MAXN][MAXN][2];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
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+1;i++)
for(int j=0;j<=n+1;j++)
for(int k=0;k<=n+1;k++)
dp[i][j][k][0]=dp[i][j][k][1]=INF;
dp[0][n+1][0][0]=dp[0][n+1][0][1]=0;
int ans=0;
for(int s=1;s<=n;s++)
{
for(int i=0;i<=s;i++)
{
int j=n-(s-i)+1;
for(int cnt=0;cnt<=s;cnt++)
{
if(i>0)
{
int time=dp[i-1][j][cnt][0];
int add=abs(x[i-1]-x[i]); add=min(add, L-add);
if(time+add<=t[i]) dp[i][j][cnt+1][0]=min(dp[i][j][cnt+1][0], time+add);
else dp[i][j][cnt][0]=min(dp[i][j][cnt][0], time+add);
time=dp[i-1][j][cnt][1];
add=abs(x[i]-x[j]); add=min(add, L-add);
if(time+add<=t[i]) dp[i][j][cnt+1][0]=min(dp[i][j][cnt+1][0], time+add);
else dp[i][j][cnt][0]=min(dp[i][j][cnt][0], time+add);
}
if(j<n+1)
{
int time=dp[i][j+1][cnt][0];
int add=abs(x[j]-x[i]); add=min(add, L-add);
if(time+add<=t[j]) dp[i][j][cnt+1][1]=min(dp[i][j][cnt+1][1], time+add);
else dp[i][j][cnt][1]=min(dp[i][j][cnt][1], time+add);
time=dp[i][j+1][cnt][1];
add=abs(x[j]-x[j+1]); add=min(add, L-add);
if(time+add<=t[j]) dp[i][j][cnt+1][1]=min(dp[i][j][cnt+1][1], time+add);
else dp[i][j][cnt][1]=min(dp[i][j][cnt][1], time+add);
}
if(dp[i][j][cnt][0]<INF || dp[i][j][cnt][1]<INF) ans=max(ans, cnt);
}
}
}
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4612 KB |
Output is correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
6652 KB |
Output is correct |
13 |
Correct |
2 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4604 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
2 ms |
6648 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4612 KB |
Output is correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
6652 KB |
Output is correct |
13 |
Correct |
2 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4604 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
2 ms |
6648 KB |
Output is correct |
18 |
Correct |
1 ms |
6480 KB |
Output is correct |
19 |
Correct |
1 ms |
4432 KB |
Output is correct |
20 |
Correct |
1 ms |
6480 KB |
Output is correct |
21 |
Correct |
1 ms |
6480 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
6480 KB |
Output is correct |
24 |
Correct |
1 ms |
6480 KB |
Output is correct |
25 |
Correct |
1 ms |
6480 KB |
Output is correct |
26 |
Correct |
1 ms |
6480 KB |
Output is correct |
27 |
Correct |
1 ms |
4432 KB |
Output is correct |
28 |
Correct |
1 ms |
4432 KB |
Output is correct |
29 |
Correct |
1 ms |
6480 KB |
Output is correct |
30 |
Correct |
1 ms |
6480 KB |
Output is correct |
31 |
Correct |
1 ms |
6480 KB |
Output is correct |
32 |
Correct |
2 ms |
6480 KB |
Output is correct |
33 |
Correct |
1 ms |
6480 KB |
Output is correct |
34 |
Correct |
1 ms |
6480 KB |
Output is correct |
35 |
Correct |
1 ms |
6480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4612 KB |
Output is correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
6652 KB |
Output is correct |
13 |
Correct |
2 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4604 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
2 ms |
6648 KB |
Output is correct |
18 |
Correct |
25 ms |
59984 KB |
Output is correct |
19 |
Correct |
14 ms |
47696 KB |
Output is correct |
20 |
Correct |
7 ms |
35408 KB |
Output is correct |
21 |
Correct |
13 ms |
45800 KB |
Output is correct |
22 |
Correct |
17 ms |
51808 KB |
Output is correct |
23 |
Correct |
7 ms |
33360 KB |
Output is correct |
24 |
Correct |
5 ms |
29432 KB |
Output is correct |
25 |
Correct |
7 ms |
31312 KB |
Output is correct |
26 |
Correct |
3 ms |
21072 KB |
Output is correct |
27 |
Correct |
7 ms |
33360 KB |
Output is correct |
28 |
Correct |
5 ms |
27216 KB |
Output is correct |
29 |
Correct |
7 ms |
33360 KB |
Output is correct |
30 |
Correct |
6 ms |
29264 KB |
Output is correct |
31 |
Correct |
7 ms |
31312 KB |
Output is correct |
32 |
Correct |
4 ms |
23120 KB |
Output is correct |
33 |
Correct |
7 ms |
31408 KB |
Output is correct |
34 |
Correct |
3 ms |
19024 KB |
Output is correct |
35 |
Correct |
6 ms |
31356 KB |
Output is correct |
36 |
Correct |
4 ms |
23120 KB |
Output is correct |
37 |
Correct |
7 ms |
33360 KB |
Output is correct |
38 |
Correct |
5 ms |
25168 KB |
Output is correct |
39 |
Correct |
7 ms |
33456 KB |
Output is correct |
40 |
Correct |
5 ms |
25168 KB |
Output is correct |
41 |
Correct |
34 ms |
66468 KB |
Output is correct |
42 |
Correct |
20 ms |
56008 KB |
Output is correct |
43 |
Correct |
32 ms |
66384 KB |
Output is correct |
44 |
Correct |
19 ms |
55888 KB |
Output is correct |
45 |
Correct |
33 ms |
66384 KB |
Output is correct |
46 |
Correct |
19 ms |
55888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
2 ms |
4432 KB |
Output is correct |
4 |
Correct |
2 ms |
4612 KB |
Output is correct |
5 |
Correct |
1 ms |
4432 KB |
Output is correct |
6 |
Correct |
1 ms |
6480 KB |
Output is correct |
7 |
Correct |
1 ms |
4432 KB |
Output is correct |
8 |
Correct |
1 ms |
4432 KB |
Output is correct |
9 |
Correct |
2 ms |
6480 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
12 |
Correct |
1 ms |
6652 KB |
Output is correct |
13 |
Correct |
2 ms |
6480 KB |
Output is correct |
14 |
Correct |
1 ms |
4432 KB |
Output is correct |
15 |
Correct |
1 ms |
4604 KB |
Output is correct |
16 |
Correct |
1 ms |
6480 KB |
Output is correct |
17 |
Correct |
2 ms |
6648 KB |
Output is correct |
18 |
Correct |
1 ms |
6480 KB |
Output is correct |
19 |
Correct |
1 ms |
4432 KB |
Output is correct |
20 |
Correct |
1 ms |
6480 KB |
Output is correct |
21 |
Correct |
1 ms |
6480 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
6480 KB |
Output is correct |
24 |
Correct |
1 ms |
6480 KB |
Output is correct |
25 |
Correct |
1 ms |
6480 KB |
Output is correct |
26 |
Correct |
1 ms |
6480 KB |
Output is correct |
27 |
Correct |
1 ms |
4432 KB |
Output is correct |
28 |
Correct |
1 ms |
4432 KB |
Output is correct |
29 |
Correct |
1 ms |
6480 KB |
Output is correct |
30 |
Correct |
1 ms |
6480 KB |
Output is correct |
31 |
Correct |
1 ms |
6480 KB |
Output is correct |
32 |
Correct |
2 ms |
6480 KB |
Output is correct |
33 |
Correct |
1 ms |
6480 KB |
Output is correct |
34 |
Correct |
1 ms |
6480 KB |
Output is correct |
35 |
Correct |
1 ms |
6480 KB |
Output is correct |
36 |
Correct |
25 ms |
59984 KB |
Output is correct |
37 |
Correct |
14 ms |
47696 KB |
Output is correct |
38 |
Correct |
7 ms |
35408 KB |
Output is correct |
39 |
Correct |
13 ms |
45800 KB |
Output is correct |
40 |
Correct |
17 ms |
51808 KB |
Output is correct |
41 |
Correct |
7 ms |
33360 KB |
Output is correct |
42 |
Correct |
5 ms |
29432 KB |
Output is correct |
43 |
Correct |
7 ms |
31312 KB |
Output is correct |
44 |
Correct |
3 ms |
21072 KB |
Output is correct |
45 |
Correct |
7 ms |
33360 KB |
Output is correct |
46 |
Correct |
5 ms |
27216 KB |
Output is correct |
47 |
Correct |
7 ms |
33360 KB |
Output is correct |
48 |
Correct |
6 ms |
29264 KB |
Output is correct |
49 |
Correct |
7 ms |
31312 KB |
Output is correct |
50 |
Correct |
4 ms |
23120 KB |
Output is correct |
51 |
Correct |
7 ms |
31408 KB |
Output is correct |
52 |
Correct |
3 ms |
19024 KB |
Output is correct |
53 |
Correct |
6 ms |
31356 KB |
Output is correct |
54 |
Correct |
4 ms |
23120 KB |
Output is correct |
55 |
Correct |
7 ms |
33360 KB |
Output is correct |
56 |
Correct |
5 ms |
25168 KB |
Output is correct |
57 |
Correct |
7 ms |
33456 KB |
Output is correct |
58 |
Correct |
5 ms |
25168 KB |
Output is correct |
59 |
Correct |
34 ms |
66468 KB |
Output is correct |
60 |
Correct |
20 ms |
56008 KB |
Output is correct |
61 |
Correct |
32 ms |
66384 KB |
Output is correct |
62 |
Correct |
19 ms |
55888 KB |
Output is correct |
63 |
Correct |
33 ms |
66384 KB |
Output is correct |
64 |
Correct |
19 ms |
55888 KB |
Output is correct |
65 |
Correct |
27 ms |
64152 KB |
Output is correct |
66 |
Correct |
26 ms |
62032 KB |
Output is correct |
67 |
Correct |
27 ms |
59996 KB |
Output is correct |
68 |
Correct |
24 ms |
57936 KB |
Output is correct |
69 |
Correct |
32 ms |
64248 KB |
Output is correct |
70 |
Correct |
27 ms |
62032 KB |
Output is correct |
71 |
Correct |
26 ms |
62032 KB |
Output is correct |
72 |
Correct |
26 ms |
64080 KB |
Output is correct |
73 |
Correct |
25 ms |
59984 KB |
Output is correct |
74 |
Correct |
23 ms |
57936 KB |
Output is correct |
75 |
Correct |
34 ms |
62104 KB |
Output is correct |
76 |
Correct |
33 ms |
66128 KB |
Output is correct |
77 |
Correct |
30 ms |
66128 KB |
Output is correct |
78 |
Correct |
25 ms |
58108 KB |
Output is correct |
79 |
Correct |
24 ms |
59984 KB |
Output is correct |
80 |
Correct |
34 ms |
66128 KB |
Output is correct |
81 |
Correct |
24 ms |
59984 KB |
Output is correct |
82 |
Correct |
26 ms |
62200 KB |
Output is correct |
83 |
Correct |
33 ms |
66592 KB |
Output is correct |
84 |
Correct |
29 ms |
62032 KB |
Output is correct |
85 |
Correct |
31 ms |
66128 KB |
Output is correct |
86 |
Correct |
31 ms |
64080 KB |
Output is correct |
87 |
Correct |
25 ms |
62032 KB |
Output is correct |
88 |
Correct |
35 ms |
66896 KB |
Output is correct |
89 |
Correct |
32 ms |
66896 KB |
Output is correct |
90 |
Correct |
25 ms |
62032 KB |
Output is correct |
91 |
Correct |
33 ms |
66756 KB |
Output is correct |
92 |
Correct |
32 ms |
66896 KB |
Output is correct |
93 |
Correct |
31 ms |
66128 KB |
Output is correct |