#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[205][205][205][2];
int X[205],T[205];
int main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N,L; cin >> N >> L;
for(int i = 1;i<=N;++i){
cin >> X[i];
}
X[N+1] = L;
for(int i = 1;i<=N;++i){
cin >> T[i];
}
int ans = 0;
memset(dp,0x3f,sizeof(dp));
ll INF = dp[0][0][0][0];
dp[0][0][0][0] = dp[0][0][0][1] = 0;
for(int l = 0;l<=N;++l){
for(int r = 0;r<=N;++r){
if(l+r >= N) break;
for(int k = 0;k<=l+r;++k){
ll tmp = dp[l][r][k][0];
if(tmp <= INF){
dp[l+1][r][k+(tmp+X[N-l+1]-X[N-l] <= T[N-l])][0] = min(dp[l+1][r][k+(tmp+X[N-l+1]-X[N-l] <= T[N-l])][0],tmp+X[N-l+1]-X[N-l]);
dp[l][r+1][k+(tmp+L-X[N-l+1]+X[r+1] <= T[r+1])][1] = min(dp[l][r+1][k+(tmp+L-X[N-l+1]+X[r+1] <= T[r+1])][1],tmp+L-X[N-l+1]+X[r+1]);
}
tmp = dp[l][r][k][1];
if(tmp <= INF){
dp[l+1][r][k+(tmp+L-X[N-l]+X[r]<=T[N-l])][0] = min(dp[l+1][r][k+(tmp+L-X[N-l]+X[r]<=T[N-l])][0],tmp+L-X[N-l]+X[r]);
dp[l][r+1][k+(tmp+X[r+1]-X[r]<=T[r+1])][1]=min(dp[l][r+1][k+(tmp+X[r+1]-X[r]<=T[r+1])][1],tmp+X[r+1]-X[r]);
}
}
}
}
for(int i = 0;i<=N;++i){
for(int j = 0;j<=N;++j){
for(int k = 0;k<=N;++k){
if(dp[i][j][k][0] != INF){
ans = max(ans,k);
}
if(dp[i][j][k][1] != INF){
ans = max(ans,k);
}
}
}
}
cout << ans << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
135252 KB |
Output is correct |
2 |
Correct |
62 ms |
135248 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
60 ms |
135252 KB |
Output is correct |
5 |
Correct |
62 ms |
135252 KB |
Output is correct |
6 |
Correct |
58 ms |
135248 KB |
Output is correct |
7 |
Correct |
63 ms |
135252 KB |
Output is correct |
8 |
Correct |
61 ms |
135252 KB |
Output is correct |
9 |
Correct |
62 ms |
135248 KB |
Output is correct |
10 |
Correct |
60 ms |
135248 KB |
Output is correct |
11 |
Correct |
66 ms |
135228 KB |
Output is correct |
12 |
Correct |
62 ms |
135060 KB |
Output is correct |
13 |
Correct |
59 ms |
135136 KB |
Output is correct |
14 |
Correct |
61 ms |
135248 KB |
Output is correct |
15 |
Correct |
60 ms |
135260 KB |
Output is correct |
16 |
Correct |
60 ms |
135252 KB |
Output is correct |
17 |
Correct |
60 ms |
135248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
135252 KB |
Output is correct |
2 |
Correct |
62 ms |
135248 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
60 ms |
135252 KB |
Output is correct |
5 |
Correct |
62 ms |
135252 KB |
Output is correct |
6 |
Correct |
58 ms |
135248 KB |
Output is correct |
7 |
Correct |
63 ms |
135252 KB |
Output is correct |
8 |
Correct |
61 ms |
135252 KB |
Output is correct |
9 |
Correct |
62 ms |
135248 KB |
Output is correct |
10 |
Correct |
60 ms |
135248 KB |
Output is correct |
11 |
Correct |
66 ms |
135228 KB |
Output is correct |
12 |
Correct |
62 ms |
135060 KB |
Output is correct |
13 |
Correct |
59 ms |
135136 KB |
Output is correct |
14 |
Correct |
61 ms |
135248 KB |
Output is correct |
15 |
Correct |
60 ms |
135260 KB |
Output is correct |
16 |
Correct |
60 ms |
135252 KB |
Output is correct |
17 |
Correct |
60 ms |
135248 KB |
Output is correct |
18 |
Correct |
63 ms |
135104 KB |
Output is correct |
19 |
Correct |
73 ms |
135272 KB |
Output is correct |
20 |
Correct |
62 ms |
135252 KB |
Output is correct |
21 |
Correct |
58 ms |
135248 KB |
Output is correct |
22 |
Correct |
65 ms |
135248 KB |
Output is correct |
23 |
Correct |
60 ms |
135264 KB |
Output is correct |
24 |
Correct |
60 ms |
135252 KB |
Output is correct |
25 |
Correct |
60 ms |
135228 KB |
Output is correct |
26 |
Correct |
60 ms |
135252 KB |
Output is correct |
27 |
Correct |
71 ms |
135076 KB |
Output is correct |
28 |
Correct |
60 ms |
135248 KB |
Output is correct |
29 |
Correct |
66 ms |
135252 KB |
Output is correct |
30 |
Correct |
65 ms |
135252 KB |
Output is correct |
31 |
Correct |
57 ms |
135288 KB |
Output is correct |
32 |
Correct |
62 ms |
135088 KB |
Output is correct |
33 |
Correct |
59 ms |
135248 KB |
Output is correct |
34 |
Correct |
61 ms |
135272 KB |
Output is correct |
35 |
Correct |
64 ms |
135248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
135252 KB |
Output is correct |
2 |
Correct |
62 ms |
135248 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
60 ms |
135252 KB |
Output is correct |
5 |
Correct |
62 ms |
135252 KB |
Output is correct |
6 |
Correct |
58 ms |
135248 KB |
Output is correct |
7 |
Correct |
63 ms |
135252 KB |
Output is correct |
8 |
Correct |
61 ms |
135252 KB |
Output is correct |
9 |
Correct |
62 ms |
135248 KB |
Output is correct |
10 |
Correct |
60 ms |
135248 KB |
Output is correct |
11 |
Correct |
66 ms |
135228 KB |
Output is correct |
12 |
Correct |
62 ms |
135060 KB |
Output is correct |
13 |
Correct |
59 ms |
135136 KB |
Output is correct |
14 |
Correct |
61 ms |
135248 KB |
Output is correct |
15 |
Correct |
60 ms |
135260 KB |
Output is correct |
16 |
Correct |
60 ms |
135252 KB |
Output is correct |
17 |
Correct |
60 ms |
135248 KB |
Output is correct |
18 |
Correct |
88 ms |
135248 KB |
Output is correct |
19 |
Correct |
84 ms |
135252 KB |
Output is correct |
20 |
Correct |
64 ms |
135068 KB |
Output is correct |
21 |
Correct |
80 ms |
135100 KB |
Output is correct |
22 |
Correct |
79 ms |
135072 KB |
Output is correct |
23 |
Correct |
64 ms |
135248 KB |
Output is correct |
24 |
Correct |
67 ms |
135224 KB |
Output is correct |
25 |
Correct |
69 ms |
135108 KB |
Output is correct |
26 |
Correct |
67 ms |
135072 KB |
Output is correct |
27 |
Correct |
76 ms |
135252 KB |
Output is correct |
28 |
Correct |
68 ms |
135248 KB |
Output is correct |
29 |
Correct |
66 ms |
135112 KB |
Output is correct |
30 |
Correct |
63 ms |
135100 KB |
Output is correct |
31 |
Correct |
71 ms |
135304 KB |
Output is correct |
32 |
Correct |
62 ms |
135192 KB |
Output is correct |
33 |
Correct |
69 ms |
135232 KB |
Output is correct |
34 |
Correct |
60 ms |
135088 KB |
Output is correct |
35 |
Correct |
68 ms |
135100 KB |
Output is correct |
36 |
Correct |
68 ms |
135224 KB |
Output is correct |
37 |
Correct |
76 ms |
135152 KB |
Output is correct |
38 |
Correct |
67 ms |
135292 KB |
Output is correct |
39 |
Correct |
76 ms |
135132 KB |
Output is correct |
40 |
Correct |
73 ms |
135136 KB |
Output is correct |
41 |
Correct |
110 ms |
135260 KB |
Output is correct |
42 |
Correct |
89 ms |
135236 KB |
Output is correct |
43 |
Correct |
104 ms |
135320 KB |
Output is correct |
44 |
Correct |
96 ms |
135140 KB |
Output is correct |
45 |
Correct |
93 ms |
135320 KB |
Output is correct |
46 |
Correct |
81 ms |
135264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
135252 KB |
Output is correct |
2 |
Correct |
62 ms |
135248 KB |
Output is correct |
3 |
Correct |
60 ms |
135248 KB |
Output is correct |
4 |
Correct |
60 ms |
135252 KB |
Output is correct |
5 |
Correct |
62 ms |
135252 KB |
Output is correct |
6 |
Correct |
58 ms |
135248 KB |
Output is correct |
7 |
Correct |
63 ms |
135252 KB |
Output is correct |
8 |
Correct |
61 ms |
135252 KB |
Output is correct |
9 |
Correct |
62 ms |
135248 KB |
Output is correct |
10 |
Correct |
60 ms |
135248 KB |
Output is correct |
11 |
Correct |
66 ms |
135228 KB |
Output is correct |
12 |
Correct |
62 ms |
135060 KB |
Output is correct |
13 |
Correct |
59 ms |
135136 KB |
Output is correct |
14 |
Correct |
61 ms |
135248 KB |
Output is correct |
15 |
Correct |
60 ms |
135260 KB |
Output is correct |
16 |
Correct |
60 ms |
135252 KB |
Output is correct |
17 |
Correct |
60 ms |
135248 KB |
Output is correct |
18 |
Correct |
63 ms |
135104 KB |
Output is correct |
19 |
Correct |
73 ms |
135272 KB |
Output is correct |
20 |
Correct |
62 ms |
135252 KB |
Output is correct |
21 |
Correct |
58 ms |
135248 KB |
Output is correct |
22 |
Correct |
65 ms |
135248 KB |
Output is correct |
23 |
Correct |
60 ms |
135264 KB |
Output is correct |
24 |
Correct |
60 ms |
135252 KB |
Output is correct |
25 |
Correct |
60 ms |
135228 KB |
Output is correct |
26 |
Correct |
60 ms |
135252 KB |
Output is correct |
27 |
Correct |
71 ms |
135076 KB |
Output is correct |
28 |
Correct |
60 ms |
135248 KB |
Output is correct |
29 |
Correct |
66 ms |
135252 KB |
Output is correct |
30 |
Correct |
65 ms |
135252 KB |
Output is correct |
31 |
Correct |
57 ms |
135288 KB |
Output is correct |
32 |
Correct |
62 ms |
135088 KB |
Output is correct |
33 |
Correct |
59 ms |
135248 KB |
Output is correct |
34 |
Correct |
61 ms |
135272 KB |
Output is correct |
35 |
Correct |
64 ms |
135248 KB |
Output is correct |
36 |
Correct |
88 ms |
135248 KB |
Output is correct |
37 |
Correct |
84 ms |
135252 KB |
Output is correct |
38 |
Correct |
64 ms |
135068 KB |
Output is correct |
39 |
Correct |
80 ms |
135100 KB |
Output is correct |
40 |
Correct |
79 ms |
135072 KB |
Output is correct |
41 |
Correct |
64 ms |
135248 KB |
Output is correct |
42 |
Correct |
67 ms |
135224 KB |
Output is correct |
43 |
Correct |
69 ms |
135108 KB |
Output is correct |
44 |
Correct |
67 ms |
135072 KB |
Output is correct |
45 |
Correct |
76 ms |
135252 KB |
Output is correct |
46 |
Correct |
68 ms |
135248 KB |
Output is correct |
47 |
Correct |
66 ms |
135112 KB |
Output is correct |
48 |
Correct |
63 ms |
135100 KB |
Output is correct |
49 |
Correct |
71 ms |
135304 KB |
Output is correct |
50 |
Correct |
62 ms |
135192 KB |
Output is correct |
51 |
Correct |
69 ms |
135232 KB |
Output is correct |
52 |
Correct |
60 ms |
135088 KB |
Output is correct |
53 |
Correct |
68 ms |
135100 KB |
Output is correct |
54 |
Correct |
68 ms |
135224 KB |
Output is correct |
55 |
Correct |
76 ms |
135152 KB |
Output is correct |
56 |
Correct |
67 ms |
135292 KB |
Output is correct |
57 |
Correct |
76 ms |
135132 KB |
Output is correct |
58 |
Correct |
73 ms |
135136 KB |
Output is correct |
59 |
Correct |
110 ms |
135260 KB |
Output is correct |
60 |
Correct |
89 ms |
135236 KB |
Output is correct |
61 |
Correct |
104 ms |
135320 KB |
Output is correct |
62 |
Correct |
96 ms |
135140 KB |
Output is correct |
63 |
Correct |
93 ms |
135320 KB |
Output is correct |
64 |
Correct |
81 ms |
135264 KB |
Output is correct |
65 |
Correct |
90 ms |
135248 KB |
Output is correct |
66 |
Correct |
87 ms |
135308 KB |
Output is correct |
67 |
Correct |
85 ms |
135252 KB |
Output is correct |
68 |
Correct |
90 ms |
135248 KB |
Output is correct |
69 |
Correct |
90 ms |
135248 KB |
Output is correct |
70 |
Correct |
88 ms |
135248 KB |
Output is correct |
71 |
Correct |
86 ms |
135252 KB |
Output is correct |
72 |
Correct |
111 ms |
135248 KB |
Output is correct |
73 |
Correct |
87 ms |
135300 KB |
Output is correct |
74 |
Correct |
86 ms |
135252 KB |
Output is correct |
75 |
Correct |
89 ms |
135252 KB |
Output is correct |
76 |
Correct |
98 ms |
135300 KB |
Output is correct |
77 |
Correct |
94 ms |
135156 KB |
Output is correct |
78 |
Correct |
88 ms |
135312 KB |
Output is correct |
79 |
Correct |
87 ms |
135268 KB |
Output is correct |
80 |
Correct |
95 ms |
135248 KB |
Output is correct |
81 |
Correct |
86 ms |
135068 KB |
Output is correct |
82 |
Correct |
88 ms |
135252 KB |
Output is correct |
83 |
Correct |
100 ms |
135248 KB |
Output is correct |
84 |
Correct |
89 ms |
135252 KB |
Output is correct |
85 |
Correct |
94 ms |
135248 KB |
Output is correct |
86 |
Correct |
93 ms |
135248 KB |
Output is correct |
87 |
Correct |
90 ms |
135308 KB |
Output is correct |
88 |
Correct |
95 ms |
135248 KB |
Output is correct |
89 |
Correct |
96 ms |
135248 KB |
Output is correct |
90 |
Correct |
89 ms |
135248 KB |
Output is correct |
91 |
Correct |
103 ms |
135508 KB |
Output is correct |
92 |
Correct |
97 ms |
135248 KB |
Output is correct |
93 |
Correct |
94 ms |
135248 KB |
Output is correct |