#include<bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
const int N = 1e6 + 69;
int n,k,l,r,ans;
ll dro,x,L;
ll A[N],T[N];
ll dp[202][202][202][2];
int main(){
cin>>n>>L;
for(int i=1;i<=n;i++){
cin>>A[i];
}
A[n+1] = L;
for(int i=1;i<=n;i++){
cin>>T[i];
}
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
for(int t=0;t<=1;t++)
dp[i][j][k][t] = 1e18;
}
}
}
dp[0][0][0][1] = dp[0][0][0][0] = 0;
for(int i=0;i<=n;i++){
for(int j=0;j<=n-i;j++){
for(int k=0;k<=i+j;k++){
x = dp[i][j][k][0];
if(x<1e18){
ans = max(k,ans);
}
dro = x + A[i+1] - A[i];
dp[i+1][j][k+(dro<=T[i+1])][0] = min(dp[i+1][j][k+(dro<=T[i+1])][0],dro);
dro = x + A[n+1-j] - A[n-j] + A[i];
dp[i][j+1][k+(dro<=T[n-j])][1] = min(dp[i][j+1][k+(dro<=T[n-j])][1],dro);
x = dp[i][j][k][1];
if(x<1e18){
ans = max(k,ans);
}
dro = x + A[i+1] - A[i] + A[n+1] - A[n+1-j];
dp[i+1][j][k+(dro<=T[i+1])][0] = min(dp[i+1][j][k+(dro<=T[i+1])][0],dro);
dro = x + A[n+1-j] - A[n-j];
dp[i][j+1][k+(dro<=T[n-j])][1] = min(dp[i][j+1][k+(dro<=T[n-j])][1],dro);
}
}
}
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1016 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
1144 KB |
Output is correct |
24 |
Correct |
6 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
6 ms |
1272 KB |
Output is correct |
30 |
Correct |
6 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1272 KB |
Output is correct |
34 |
Correct |
5 ms |
1176 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
92 ms |
103532 KB |
Output is correct |
19 |
Correct |
55 ms |
62772 KB |
Output is correct |
20 |
Correct |
33 ms |
33532 KB |
Output is correct |
21 |
Correct |
57 ms |
59256 KB |
Output is correct |
22 |
Correct |
71 ms |
76792 KB |
Output is correct |
23 |
Correct |
24 ms |
28536 KB |
Output is correct |
24 |
Correct |
21 ms |
22392 KB |
Output is correct |
25 |
Correct |
37 ms |
27896 KB |
Output is correct |
26 |
Correct |
11 ms |
10744 KB |
Output is correct |
27 |
Correct |
28 ms |
29176 KB |
Output is correct |
28 |
Correct |
19 ms |
20856 KB |
Output is correct |
29 |
Incorrect |
25 ms |
29816 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Correct |
5 ms |
504 KB |
Output is correct |
3 |
Correct |
5 ms |
632 KB |
Output is correct |
4 |
Correct |
5 ms |
504 KB |
Output is correct |
5 |
Correct |
5 ms |
636 KB |
Output is correct |
6 |
Correct |
5 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
632 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
5 ms |
888 KB |
Output is correct |
10 |
Correct |
4 ms |
376 KB |
Output is correct |
11 |
Correct |
5 ms |
376 KB |
Output is correct |
12 |
Correct |
6 ms |
888 KB |
Output is correct |
13 |
Correct |
5 ms |
888 KB |
Output is correct |
14 |
Correct |
5 ms |
504 KB |
Output is correct |
15 |
Correct |
5 ms |
632 KB |
Output is correct |
16 |
Correct |
5 ms |
888 KB |
Output is correct |
17 |
Correct |
5 ms |
888 KB |
Output is correct |
18 |
Correct |
5 ms |
1144 KB |
Output is correct |
19 |
Correct |
5 ms |
760 KB |
Output is correct |
20 |
Correct |
5 ms |
888 KB |
Output is correct |
21 |
Correct |
5 ms |
1016 KB |
Output is correct |
22 |
Correct |
5 ms |
632 KB |
Output is correct |
23 |
Correct |
5 ms |
1144 KB |
Output is correct |
24 |
Correct |
6 ms |
1016 KB |
Output is correct |
25 |
Correct |
5 ms |
1144 KB |
Output is correct |
26 |
Correct |
5 ms |
1144 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
5 ms |
760 KB |
Output is correct |
29 |
Correct |
6 ms |
1272 KB |
Output is correct |
30 |
Correct |
6 ms |
1144 KB |
Output is correct |
31 |
Correct |
5 ms |
1144 KB |
Output is correct |
32 |
Correct |
5 ms |
1016 KB |
Output is correct |
33 |
Correct |
5 ms |
1272 KB |
Output is correct |
34 |
Correct |
5 ms |
1176 KB |
Output is correct |
35 |
Correct |
5 ms |
1144 KB |
Output is correct |
36 |
Correct |
92 ms |
103532 KB |
Output is correct |
37 |
Correct |
55 ms |
62772 KB |
Output is correct |
38 |
Correct |
33 ms |
33532 KB |
Output is correct |
39 |
Correct |
57 ms |
59256 KB |
Output is correct |
40 |
Correct |
71 ms |
76792 KB |
Output is correct |
41 |
Correct |
24 ms |
28536 KB |
Output is correct |
42 |
Correct |
21 ms |
22392 KB |
Output is correct |
43 |
Correct |
37 ms |
27896 KB |
Output is correct |
44 |
Correct |
11 ms |
10744 KB |
Output is correct |
45 |
Correct |
28 ms |
29176 KB |
Output is correct |
46 |
Correct |
19 ms |
20856 KB |
Output is correct |
47 |
Incorrect |
25 ms |
29816 KB |
Output isn't correct |
48 |
Halted |
0 ms |
0 KB |
- |