#include<bits/stdc++.h>
using namespace std;
const int N = 200;
const int inf = 1e9 + 10;
int v[N + 2];
int v2[N + 2];
int dp[N + 3][N + 3][N + 3][2];
int main(){
int n,nr;
int ans = 0;
cin>>n>>nr;
v[0] = 0;
v2[0] = 100;
for(int i = 1;i <= n;i++){
cin>>v[i];
}
for(int i = 1;i <= n;i++){
cin>>v2[i];
}
v[n + 1] = nr;
v2[n + 1] = 100;
n+=2;
for(int i = 0;i <= n;i++){
for(int j = 0;j <= i;j++){
for(int k = 0;k <= i;k++){
for(int p = 0;p <= 1;p++){
if(i == 0 && j == 0 && k == 0 && p == 0){
dp[i][j][k][p] = 0;
}else{
dp[i][j][k][p] = inf;
int leftid = n - 1 - (i - j);
int rightid = j;
int dist = v[rightid] + (nr - v[leftid]);
if(i == 0 || leftid <= rightid)continue;
if(p == 0){
if(leftid == n - 1)continue;
///to leftside
///from rightside
if(k != 0 && dist + dp[i - 1][j][k - 1][1] <= v2[leftid]){
dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j][k - 1][1]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j][k][1]);
}
///from leftside
if(k != 0 && dp[i - 1][j][k - 1][0] + v[leftid + 1] - v[leftid] <= v2[leftid]){
dp[i][j][k][p] = min(dp[i][j][k][p],dp[i - 1][j][k - 1][0] + v[leftid + 1] - v[leftid]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dp[i - 1][j][k][0] + v[leftid + 1] - v[leftid]);
}
}else{
if(j == 0 || rightid == n)continue;
///to rightside
///from leftside
if(k != 0 && dist + dp[i - 1][j - 1][k - 1][0] <= v2[rightid]){
dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j - 1][k - 1][0]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],dist + dp[i - 1][j - 1][k][0]);
}
///from rightside
if(k != 0 && (v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k - 1][1] <= v2[rightid]){
dp[i][j][k][p] = min(dp[i][j][k][p],(v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k - 1][1]);
}else{
if(i != k)dp[i][j][k][p] = min(dp[i][j][k][p],(v[rightid] - v[rightid - 1]) + dp[i - 1][j - 1][k][1]);
}
}
if(dp[i][j][k][p] != inf){
ans = max(ans,k);
}
//cout<<dp[i][j][k][p]<<' '<<i<<' '<<j<<' '<<k<<' '<<p<<' '<<dist<<' '<<leftid<<' '<<v[leftid + 1]<<' '<<v[leftid]<<' '<<(v[rightid] - v[rightid - 1])<<'\n';
}
}
}
}
}
cout<<ans<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
0 ms |
2648 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
0 ms |
2648 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
4440 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6588 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6488 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
0 ms |
2648 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
38 ms |
47080 KB |
Output is correct |
19 |
Correct |
16 ms |
36540 KB |
Output is correct |
20 |
Correct |
7 ms |
27740 KB |
Output is correct |
21 |
Correct |
14 ms |
35748 KB |
Output is correct |
22 |
Correct |
20 ms |
38748 KB |
Output is correct |
23 |
Correct |
6 ms |
27740 KB |
Output is correct |
24 |
Correct |
5 ms |
25948 KB |
Output is correct |
25 |
Correct |
8 ms |
26076 KB |
Output is correct |
26 |
Correct |
3 ms |
20828 KB |
Output is correct |
27 |
Correct |
6 ms |
27812 KB |
Output is correct |
28 |
Correct |
6 ms |
24156 KB |
Output is correct |
29 |
Correct |
9 ms |
26716 KB |
Output is correct |
30 |
Correct |
8 ms |
27372 KB |
Output is correct |
31 |
Correct |
6 ms |
26076 KB |
Output is correct |
32 |
Correct |
3 ms |
22876 KB |
Output is correct |
33 |
Correct |
6 ms |
27484 KB |
Output is correct |
34 |
Correct |
2 ms |
18780 KB |
Output is correct |
35 |
Correct |
5 ms |
28508 KB |
Output is correct |
36 |
Correct |
3 ms |
23000 KB |
Output is correct |
37 |
Correct |
6 ms |
27740 KB |
Output is correct |
38 |
Correct |
3 ms |
24920 KB |
Output is correct |
39 |
Correct |
6 ms |
29272 KB |
Output is correct |
40 |
Correct |
4 ms |
24924 KB |
Output is correct |
41 |
Correct |
39 ms |
51972 KB |
Output is correct |
42 |
Correct |
30 ms |
41304 KB |
Output is correct |
43 |
Correct |
50 ms |
53092 KB |
Output is correct |
44 |
Correct |
21 ms |
42256 KB |
Output is correct |
45 |
Correct |
39 ms |
51856 KB |
Output is correct |
46 |
Correct |
22 ms |
42584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
0 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
0 ms |
4444 KB |
Output is correct |
8 |
Correct |
0 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
0 ms |
2648 KB |
Output is correct |
11 |
Correct |
0 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
6492 KB |
Output is correct |
13 |
Correct |
1 ms |
6492 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
0 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
6492 KB |
Output is correct |
17 |
Correct |
1 ms |
6492 KB |
Output is correct |
18 |
Correct |
1 ms |
6492 KB |
Output is correct |
19 |
Correct |
0 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
6492 KB |
Output is correct |
21 |
Correct |
1 ms |
6492 KB |
Output is correct |
22 |
Correct |
1 ms |
4440 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
1 ms |
6492 KB |
Output is correct |
25 |
Correct |
1 ms |
6588 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
6492 KB |
Output is correct |
30 |
Correct |
1 ms |
6492 KB |
Output is correct |
31 |
Correct |
1 ms |
6492 KB |
Output is correct |
32 |
Correct |
1 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6488 KB |
Output is correct |
34 |
Correct |
1 ms |
6492 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
38 ms |
47080 KB |
Output is correct |
37 |
Correct |
16 ms |
36540 KB |
Output is correct |
38 |
Correct |
7 ms |
27740 KB |
Output is correct |
39 |
Correct |
14 ms |
35748 KB |
Output is correct |
40 |
Correct |
20 ms |
38748 KB |
Output is correct |
41 |
Correct |
6 ms |
27740 KB |
Output is correct |
42 |
Correct |
5 ms |
25948 KB |
Output is correct |
43 |
Correct |
8 ms |
26076 KB |
Output is correct |
44 |
Correct |
3 ms |
20828 KB |
Output is correct |
45 |
Correct |
6 ms |
27812 KB |
Output is correct |
46 |
Correct |
6 ms |
24156 KB |
Output is correct |
47 |
Correct |
9 ms |
26716 KB |
Output is correct |
48 |
Correct |
8 ms |
27372 KB |
Output is correct |
49 |
Correct |
6 ms |
26076 KB |
Output is correct |
50 |
Correct |
3 ms |
22876 KB |
Output is correct |
51 |
Correct |
6 ms |
27484 KB |
Output is correct |
52 |
Correct |
2 ms |
18780 KB |
Output is correct |
53 |
Correct |
5 ms |
28508 KB |
Output is correct |
54 |
Correct |
3 ms |
23000 KB |
Output is correct |
55 |
Correct |
6 ms |
27740 KB |
Output is correct |
56 |
Correct |
3 ms |
24920 KB |
Output is correct |
57 |
Correct |
6 ms |
29272 KB |
Output is correct |
58 |
Correct |
4 ms |
24924 KB |
Output is correct |
59 |
Correct |
39 ms |
51972 KB |
Output is correct |
60 |
Correct |
30 ms |
41304 KB |
Output is correct |
61 |
Correct |
50 ms |
53092 KB |
Output is correct |
62 |
Correct |
21 ms |
42256 KB |
Output is correct |
63 |
Correct |
39 ms |
51856 KB |
Output is correct |
64 |
Correct |
22 ms |
42584 KB |
Output is correct |
65 |
Correct |
33 ms |
48732 KB |
Output is correct |
66 |
Correct |
39 ms |
46172 KB |
Output is correct |
67 |
Correct |
28 ms |
46424 KB |
Output is correct |
68 |
Correct |
25 ms |
44380 KB |
Output is correct |
69 |
Correct |
45 ms |
48312 KB |
Output is correct |
70 |
Correct |
28 ms |
47196 KB |
Output is correct |
71 |
Correct |
31 ms |
47492 KB |
Output is correct |
72 |
Correct |
29 ms |
49244 KB |
Output is correct |
73 |
Correct |
28 ms |
46932 KB |
Output is correct |
74 |
Correct |
27 ms |
45404 KB |
Output is correct |
75 |
Correct |
29 ms |
46576 KB |
Output is correct |
76 |
Correct |
34 ms |
51800 KB |
Output is correct |
77 |
Correct |
35 ms |
50516 KB |
Output is correct |
78 |
Correct |
24 ms |
44636 KB |
Output is correct |
79 |
Correct |
26 ms |
44116 KB |
Output is correct |
80 |
Correct |
33 ms |
50008 KB |
Output is correct |
81 |
Correct |
26 ms |
46936 KB |
Output is correct |
82 |
Correct |
29 ms |
47328 KB |
Output is correct |
83 |
Correct |
43 ms |
53168 KB |
Output is correct |
84 |
Correct |
40 ms |
49748 KB |
Output is correct |
85 |
Correct |
33 ms |
51028 KB |
Output is correct |
86 |
Correct |
33 ms |
50260 KB |
Output is correct |
87 |
Correct |
29 ms |
48980 KB |
Output is correct |
88 |
Correct |
37 ms |
54616 KB |
Output is correct |
89 |
Correct |
43 ms |
54616 KB |
Output is correct |
90 |
Correct |
29 ms |
49392 KB |
Output is correct |
91 |
Correct |
45 ms |
53588 KB |
Output is correct |
92 |
Correct |
50 ms |
54612 KB |
Output is correct |
93 |
Correct |
50 ms |
52816 KB |
Output is correct |