#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
ll dpl[205][205][205];
ll dpr[205][205][205];
/*
dpl[i][j][k] = min(dpl[i+1][j][k-1]+x])
*/
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
ll n,L;
cin>>n>>L;
ll x[n+2]={0};
ll t[n+2]={0};
for(int i=1;i<=n;i++) cin>>x[i];
for(int i=1;i<=n;i++) cin>>t[i];
x[n+1]=L;
for(int l=0;l<=n+1;l++){
for(int r=0;r<=n+1;r++){
for(int k=0;k<=n;k++){
dpl[l][r][k]=1e17;
dpr[l][r][k]=1e17;
}
}
}
dpl[0][n+1][0]=0;
dpr[0][n+1][0]=0;
for(int l=0;l<n;l++){
for(int r=n+1;r>=l+2;r--){
for(int k=0;k<=n;k++){
ll ti = min(dpl[l][r][k]+x[l+1]-x[l],dpr[l][r][k]+L-x[r]+x[l+1]);
dpl[l+1][r][k+(ti<=t[l+1])] = min(dpl[l+1][r][k+(ti<=t[l+1])],ti);
ti = min(dpl[l][r][k]+L-x[r-1]+x[l],dpr[l][r][k]+x[r]-x[r-1]);
dpr[l][r-1][k+(ti<=t[r-1])] = min(dpr[l][r-1][k+(ti<=t[r-1])],ti);
}
}
}
int ans = 0;
for(int i=0;i<=n+1;i++){
for(int j=0;j<=n+1;j++){
for(int k=0;k<=n;k++){
//cout<<dpl[i][j][k]<<":"<<i<<","<<j<<","<<k<<"\n";
if(dpl[i][j][k]<1e17) ans = max(ans,k);
if(dpr[i][j][k]<1e17) ans = max(ans,k);
}
}
}
cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
12632 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
2 ms |
12632 KB |
Output is correct |
14 |
Correct |
2 ms |
10584 KB |
Output is correct |
15 |
Correct |
1 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
12632 KB |
Output is correct |
17 |
Correct |
2 ms |
12632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
12632 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
2 ms |
12632 KB |
Output is correct |
14 |
Correct |
2 ms |
10584 KB |
Output is correct |
15 |
Correct |
1 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
12632 KB |
Output is correct |
17 |
Correct |
2 ms |
12632 KB |
Output is correct |
18 |
Correct |
2 ms |
14680 KB |
Output is correct |
19 |
Correct |
1 ms |
10584 KB |
Output is correct |
20 |
Correct |
2 ms |
12632 KB |
Output is correct |
21 |
Correct |
2 ms |
14680 KB |
Output is correct |
22 |
Correct |
1 ms |
10584 KB |
Output is correct |
23 |
Correct |
2 ms |
14680 KB |
Output is correct |
24 |
Correct |
2 ms |
14680 KB |
Output is correct |
25 |
Correct |
2 ms |
14680 KB |
Output is correct |
26 |
Correct |
2 ms |
14688 KB |
Output is correct |
27 |
Correct |
2 ms |
10584 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
2 ms |
14684 KB |
Output is correct |
30 |
Correct |
2 ms |
14792 KB |
Output is correct |
31 |
Correct |
2 ms |
14796 KB |
Output is correct |
32 |
Correct |
2 ms |
14680 KB |
Output is correct |
33 |
Correct |
2 ms |
14940 KB |
Output is correct |
34 |
Correct |
2 ms |
14680 KB |
Output is correct |
35 |
Correct |
2 ms |
14680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
12632 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
2 ms |
12632 KB |
Output is correct |
14 |
Correct |
2 ms |
10584 KB |
Output is correct |
15 |
Correct |
1 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
12632 KB |
Output is correct |
17 |
Correct |
2 ms |
12632 KB |
Output is correct |
18 |
Correct |
48 ms |
121688 KB |
Output is correct |
19 |
Correct |
28 ms |
96856 KB |
Output is correct |
20 |
Correct |
16 ms |
72280 KB |
Output is correct |
21 |
Correct |
26 ms |
92760 KB |
Output is correct |
22 |
Correct |
37 ms |
105424 KB |
Output is correct |
23 |
Correct |
14 ms |
66136 KB |
Output is correct |
24 |
Correct |
11 ms |
59992 KB |
Output is correct |
25 |
Correct |
13 ms |
64092 KB |
Output is correct |
26 |
Correct |
6 ms |
41560 KB |
Output is correct |
27 |
Correct |
14 ms |
68184 KB |
Output is correct |
28 |
Correct |
10 ms |
55896 KB |
Output is correct |
29 |
Correct |
14 ms |
68184 KB |
Output is correct |
30 |
Correct |
12 ms |
59992 KB |
Output is correct |
31 |
Correct |
14 ms |
64092 KB |
Output is correct |
32 |
Correct |
7 ms |
47704 KB |
Output is correct |
33 |
Correct |
16 ms |
64088 KB |
Output is correct |
34 |
Correct |
6 ms |
39512 KB |
Output is correct |
35 |
Correct |
13 ms |
64088 KB |
Output is correct |
36 |
Correct |
7 ms |
45656 KB |
Output is correct |
37 |
Correct |
14 ms |
68184 KB |
Output is correct |
38 |
Correct |
9 ms |
51872 KB |
Output is correct |
39 |
Correct |
14 ms |
68184 KB |
Output is correct |
40 |
Correct |
9 ms |
51804 KB |
Output is correct |
41 |
Correct |
55 ms |
133972 KB |
Output is correct |
42 |
Correct |
34 ms |
113496 KB |
Output is correct |
43 |
Correct |
53 ms |
134012 KB |
Output is correct |
44 |
Correct |
35 ms |
113496 KB |
Output is correct |
45 |
Correct |
55 ms |
133976 KB |
Output is correct |
46 |
Correct |
33 ms |
113496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6488 KB |
Output is correct |
3 |
Correct |
1 ms |
10588 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
10584 KB |
Output is correct |
6 |
Correct |
2 ms |
12632 KB |
Output is correct |
7 |
Correct |
1 ms |
10584 KB |
Output is correct |
8 |
Correct |
1 ms |
10584 KB |
Output is correct |
9 |
Correct |
2 ms |
12632 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6488 KB |
Output is correct |
12 |
Correct |
2 ms |
12632 KB |
Output is correct |
13 |
Correct |
2 ms |
12632 KB |
Output is correct |
14 |
Correct |
2 ms |
10584 KB |
Output is correct |
15 |
Correct |
1 ms |
10584 KB |
Output is correct |
16 |
Correct |
2 ms |
12632 KB |
Output is correct |
17 |
Correct |
2 ms |
12632 KB |
Output is correct |
18 |
Correct |
2 ms |
14680 KB |
Output is correct |
19 |
Correct |
1 ms |
10584 KB |
Output is correct |
20 |
Correct |
2 ms |
12632 KB |
Output is correct |
21 |
Correct |
2 ms |
14680 KB |
Output is correct |
22 |
Correct |
1 ms |
10584 KB |
Output is correct |
23 |
Correct |
2 ms |
14680 KB |
Output is correct |
24 |
Correct |
2 ms |
14680 KB |
Output is correct |
25 |
Correct |
2 ms |
14680 KB |
Output is correct |
26 |
Correct |
2 ms |
14688 KB |
Output is correct |
27 |
Correct |
2 ms |
10584 KB |
Output is correct |
28 |
Correct |
2 ms |
10588 KB |
Output is correct |
29 |
Correct |
2 ms |
14684 KB |
Output is correct |
30 |
Correct |
2 ms |
14792 KB |
Output is correct |
31 |
Correct |
2 ms |
14796 KB |
Output is correct |
32 |
Correct |
2 ms |
14680 KB |
Output is correct |
33 |
Correct |
2 ms |
14940 KB |
Output is correct |
34 |
Correct |
2 ms |
14680 KB |
Output is correct |
35 |
Correct |
2 ms |
14680 KB |
Output is correct |
36 |
Correct |
48 ms |
121688 KB |
Output is correct |
37 |
Correct |
28 ms |
96856 KB |
Output is correct |
38 |
Correct |
16 ms |
72280 KB |
Output is correct |
39 |
Correct |
26 ms |
92760 KB |
Output is correct |
40 |
Correct |
37 ms |
105424 KB |
Output is correct |
41 |
Correct |
14 ms |
66136 KB |
Output is correct |
42 |
Correct |
11 ms |
59992 KB |
Output is correct |
43 |
Correct |
13 ms |
64092 KB |
Output is correct |
44 |
Correct |
6 ms |
41560 KB |
Output is correct |
45 |
Correct |
14 ms |
68184 KB |
Output is correct |
46 |
Correct |
10 ms |
55896 KB |
Output is correct |
47 |
Correct |
14 ms |
68184 KB |
Output is correct |
48 |
Correct |
12 ms |
59992 KB |
Output is correct |
49 |
Correct |
14 ms |
64092 KB |
Output is correct |
50 |
Correct |
7 ms |
47704 KB |
Output is correct |
51 |
Correct |
16 ms |
64088 KB |
Output is correct |
52 |
Correct |
6 ms |
39512 KB |
Output is correct |
53 |
Correct |
13 ms |
64088 KB |
Output is correct |
54 |
Correct |
7 ms |
45656 KB |
Output is correct |
55 |
Correct |
14 ms |
68184 KB |
Output is correct |
56 |
Correct |
9 ms |
51872 KB |
Output is correct |
57 |
Correct |
14 ms |
68184 KB |
Output is correct |
58 |
Correct |
9 ms |
51804 KB |
Output is correct |
59 |
Correct |
55 ms |
133972 KB |
Output is correct |
60 |
Correct |
34 ms |
113496 KB |
Output is correct |
61 |
Correct |
53 ms |
134012 KB |
Output is correct |
62 |
Correct |
35 ms |
113496 KB |
Output is correct |
63 |
Correct |
55 ms |
133976 KB |
Output is correct |
64 |
Correct |
33 ms |
113496 KB |
Output is correct |
65 |
Correct |
50 ms |
129872 KB |
Output is correct |
66 |
Correct |
45 ms |
125792 KB |
Output is correct |
67 |
Correct |
45 ms |
121688 KB |
Output is correct |
68 |
Correct |
38 ms |
117596 KB |
Output is correct |
69 |
Correct |
48 ms |
129880 KB |
Output is correct |
70 |
Correct |
46 ms |
125784 KB |
Output is correct |
71 |
Correct |
50 ms |
125776 KB |
Output is correct |
72 |
Correct |
48 ms |
127832 KB |
Output is correct |
73 |
Correct |
42 ms |
121688 KB |
Output is correct |
74 |
Correct |
41 ms |
117592 KB |
Output is correct |
75 |
Correct |
44 ms |
125784 KB |
Output is correct |
76 |
Correct |
58 ms |
133976 KB |
Output is correct |
77 |
Correct |
52 ms |
134000 KB |
Output is correct |
78 |
Correct |
40 ms |
117592 KB |
Output is correct |
79 |
Correct |
41 ms |
119640 KB |
Output is correct |
80 |
Correct |
53 ms |
133968 KB |
Output is correct |
81 |
Correct |
41 ms |
121688 KB |
Output is correct |
82 |
Correct |
50 ms |
123716 KB |
Output is correct |
83 |
Correct |
58 ms |
134232 KB |
Output is correct |
84 |
Correct |
46 ms |
125800 KB |
Output is correct |
85 |
Correct |
55 ms |
131928 KB |
Output is correct |
86 |
Correct |
50 ms |
129880 KB |
Output is correct |
87 |
Correct |
47 ms |
125784 KB |
Output is correct |
88 |
Correct |
54 ms |
134328 KB |
Output is correct |
89 |
Correct |
64 ms |
134320 KB |
Output is correct |
90 |
Correct |
46 ms |
126032 KB |
Output is correct |
91 |
Correct |
54 ms |
134224 KB |
Output is correct |
92 |
Correct |
54 ms |
134232 KB |
Output is correct |
93 |
Correct |
53 ms |
134004 KB |
Output is correct |