#include <iostream>
#include <algorithm>
using namespace std;
template<class T> T &chmin(T &a,const T &b){ return a = min(a,b); }
template<class T> T &chmax(T &a,const T &b){ return a = max(a,b); }
using ll = long long;
const ll INF = 1e18;
ll dp[210][210][2][210];
signed main(){
int n;
ll l,x[210] = {},t[210];
cin >> n >> l;
for(int i = 0;i < n;i++) cin >> x[i + 1];
for(int i = 0;i < n;i++) cin >> t[i + 1];
x[n + 1] = l;
for(int i = 0;i <= n + 1;i++){
for(int j = 0;j <= n + 1;j++){
for(int k = 0;k < 2;k++){
for(int m = 0;m <= n;m++) dp[i][j][k][m] = INF;
}
}
}
dp[0][n + 1][0][0] = dp[0][n + 1][1][0] = 0;
for(int i = 0;i < n;i++){
for(int j = n + 1;j >= i + 2;j--){
for(int m = 0;m <= n;m++){
ll tim = min(dp[i][j][0][m]+x[i+1]-x[i],dp[i][j][1][m]+l-x[j]+x[i+1]);
chmin(dp[i + 1][j][0][m + (tim <= t[i + 1])],tim);
tim = min(dp[i][j][0][m]+l-x[j-1]+x[i],dp[i][j][1][m]+x[j]-x[j-1]);
chmin(dp[i][j - 1][1][m + (tim <= t[j - 1])],tim);
}
}
}
int ans = 0;
for(int i = 0;i <= n + 1;i++){
for(int j = 0;j <= n + 1;j++){
for(int k = 0;k < 2;k++){
for(int m = 0;m <= n;m++){
if(dp[i][j][k][m] != INF) chmax(ans,m);
}
}
}
}
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
18 |
Correct |
1 ms |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
888 KB |
Output is correct |
20 |
Correct |
1 ms |
1024 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 KB |
Output is correct |
22 |
Correct |
1 ms |
768 KB |
Output is correct |
23 |
Correct |
1 ms |
1280 KB |
Output is correct |
24 |
Correct |
1 ms |
1152 KB |
Output is correct |
25 |
Correct |
1 ms |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
1152 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
1 ms |
1280 KB |
Output is correct |
30 |
Correct |
1 ms |
1280 KB |
Output is correct |
31 |
Correct |
1 ms |
1152 KB |
Output is correct |
32 |
Correct |
1 ms |
1152 KB |
Output is correct |
33 |
Correct |
1 ms |
1280 KB |
Output is correct |
34 |
Correct |
1 ms |
1280 KB |
Output is correct |
35 |
Correct |
1 ms |
1280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
18 |
Correct |
113 ms |
108792 KB |
Output is correct |
19 |
Correct |
64 ms |
66280 KB |
Output is correct |
20 |
Correct |
38 ms |
35576 KB |
Output is correct |
21 |
Correct |
68 ms |
62716 KB |
Output is correct |
22 |
Correct |
81 ms |
80888 KB |
Output is correct |
23 |
Correct |
26 ms |
30336 KB |
Output is correct |
24 |
Correct |
20 ms |
23808 KB |
Output is correct |
25 |
Correct |
26 ms |
29696 KB |
Output is correct |
26 |
Correct |
11 ms |
11640 KB |
Output is correct |
27 |
Correct |
28 ms |
30976 KB |
Output is correct |
28 |
Correct |
19 ms |
22144 KB |
Output is correct |
29 |
Correct |
27 ms |
31616 KB |
Output is correct |
30 |
Correct |
21 ms |
24960 KB |
Output is correct |
31 |
Correct |
26 ms |
29696 KB |
Output is correct |
32 |
Correct |
12 ms |
15744 KB |
Output is correct |
33 |
Correct |
26 ms |
29696 KB |
Output is correct |
34 |
Correct |
8 ms |
10880 KB |
Output is correct |
35 |
Correct |
32 ms |
29056 KB |
Output is correct |
36 |
Correct |
11 ms |
14080 KB |
Output is correct |
37 |
Correct |
27 ms |
30976 KB |
Output is correct |
38 |
Correct |
17 ms |
17152 KB |
Output is correct |
39 |
Correct |
28 ms |
32256 KB |
Output is correct |
40 |
Correct |
16 ms |
19072 KB |
Output is correct |
41 |
Correct |
153 ms |
133992 KB |
Output is correct |
42 |
Correct |
93 ms |
90616 KB |
Output is correct |
43 |
Correct |
146 ms |
133880 KB |
Output is correct |
44 |
Correct |
93 ms |
89464 KB |
Output is correct |
45 |
Correct |
147 ms |
133984 KB |
Output is correct |
46 |
Correct |
93 ms |
90616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
512 KB |
Output is correct |
2 |
Correct |
0 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
768 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
1024 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
896 KB |
Output is correct |
9 |
Correct |
1 ms |
1024 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
1024 KB |
Output is correct |
13 |
Correct |
1 ms |
1024 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
1024 KB |
Output is correct |
17 |
Correct |
1 ms |
1024 KB |
Output is correct |
18 |
Correct |
1 ms |
1152 KB |
Output is correct |
19 |
Correct |
1 ms |
888 KB |
Output is correct |
20 |
Correct |
1 ms |
1024 KB |
Output is correct |
21 |
Correct |
1 ms |
1152 KB |
Output is correct |
22 |
Correct |
1 ms |
768 KB |
Output is correct |
23 |
Correct |
1 ms |
1280 KB |
Output is correct |
24 |
Correct |
1 ms |
1152 KB |
Output is correct |
25 |
Correct |
1 ms |
1152 KB |
Output is correct |
26 |
Correct |
1 ms |
1152 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
768 KB |
Output is correct |
29 |
Correct |
1 ms |
1280 KB |
Output is correct |
30 |
Correct |
1 ms |
1280 KB |
Output is correct |
31 |
Correct |
1 ms |
1152 KB |
Output is correct |
32 |
Correct |
1 ms |
1152 KB |
Output is correct |
33 |
Correct |
1 ms |
1280 KB |
Output is correct |
34 |
Correct |
1 ms |
1280 KB |
Output is correct |
35 |
Correct |
1 ms |
1280 KB |
Output is correct |
36 |
Correct |
113 ms |
108792 KB |
Output is correct |
37 |
Correct |
64 ms |
66280 KB |
Output is correct |
38 |
Correct |
38 ms |
35576 KB |
Output is correct |
39 |
Correct |
68 ms |
62716 KB |
Output is correct |
40 |
Correct |
81 ms |
80888 KB |
Output is correct |
41 |
Correct |
26 ms |
30336 KB |
Output is correct |
42 |
Correct |
20 ms |
23808 KB |
Output is correct |
43 |
Correct |
26 ms |
29696 KB |
Output is correct |
44 |
Correct |
11 ms |
11640 KB |
Output is correct |
45 |
Correct |
28 ms |
30976 KB |
Output is correct |
46 |
Correct |
19 ms |
22144 KB |
Output is correct |
47 |
Correct |
27 ms |
31616 KB |
Output is correct |
48 |
Correct |
21 ms |
24960 KB |
Output is correct |
49 |
Correct |
26 ms |
29696 KB |
Output is correct |
50 |
Correct |
12 ms |
15744 KB |
Output is correct |
51 |
Correct |
26 ms |
29696 KB |
Output is correct |
52 |
Correct |
8 ms |
10880 KB |
Output is correct |
53 |
Correct |
32 ms |
29056 KB |
Output is correct |
54 |
Correct |
11 ms |
14080 KB |
Output is correct |
55 |
Correct |
27 ms |
30976 KB |
Output is correct |
56 |
Correct |
17 ms |
17152 KB |
Output is correct |
57 |
Correct |
28 ms |
32256 KB |
Output is correct |
58 |
Correct |
16 ms |
19072 KB |
Output is correct |
59 |
Correct |
153 ms |
133992 KB |
Output is correct |
60 |
Correct |
93 ms |
90616 KB |
Output is correct |
61 |
Correct |
146 ms |
133880 KB |
Output is correct |
62 |
Correct |
93 ms |
89464 KB |
Output is correct |
63 |
Correct |
147 ms |
133984 KB |
Output is correct |
64 |
Correct |
93 ms |
90616 KB |
Output is correct |
65 |
Correct |
133 ms |
121080 KB |
Output is correct |
66 |
Correct |
119 ms |
111188 KB |
Output is correct |
67 |
Correct |
116 ms |
106404 KB |
Output is correct |
68 |
Correct |
100 ms |
98296 KB |
Output is correct |
69 |
Correct |
143 ms |
119800 KB |
Output is correct |
70 |
Correct |
134 ms |
114808 KB |
Output is correct |
71 |
Correct |
114 ms |
115960 KB |
Output is correct |
72 |
Correct |
124 ms |
117240 KB |
Output is correct |
73 |
Correct |
113 ms |
108792 KB |
Output is correct |
74 |
Correct |
119 ms |
101624 KB |
Output is correct |
75 |
Correct |
133 ms |
112376 KB |
Output is correct |
76 |
Correct |
157 ms |
128632 KB |
Output is correct |
77 |
Correct |
152 ms |
128760 KB |
Output is correct |
78 |
Correct |
115 ms |
99448 KB |
Output is correct |
79 |
Correct |
118 ms |
102904 KB |
Output is correct |
80 |
Correct |
132 ms |
126064 KB |
Output is correct |
81 |
Correct |
120 ms |
104184 KB |
Output is correct |
82 |
Correct |
130 ms |
109944 KB |
Output is correct |
83 |
Correct |
161 ms |
133880 KB |
Output is correct |
84 |
Correct |
137 ms |
114808 KB |
Output is correct |
85 |
Correct |
135 ms |
124832 KB |
Output is correct |
86 |
Correct |
131 ms |
122232 KB |
Output is correct |
87 |
Correct |
111 ms |
112376 KB |
Output is correct |
88 |
Correct |
148 ms |
135288 KB |
Output is correct |
89 |
Correct |
150 ms |
135292 KB |
Output is correct |
90 |
Correct |
119 ms |
113532 KB |
Output is correct |
91 |
Correct |
149 ms |
135288 KB |
Output is correct |
92 |
Correct |
148 ms |
135288 KB |
Output is correct |
93 |
Correct |
148 ms |
132728 KB |
Output is correct |