#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=1e18;
ll n,l,dpl[210][210][210],dpr[210][210][210],x[210],t[210];
ll dis(int a,int b){
if(a<b)swap(a,b);
return min(x[a]-x[b],x[b]-x[a]+l);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int ans=0;
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];
for(int i=0;i<=n;i++){
for(int j=0;j<=n;j++){
for(int k=0;k<=n;k++){
dpl[i][j][k]=maxn;
dpr[i][j][k]=maxn;
}
}
}
for(int i=0;i<=n;i++){
dpl[0][i][0]=0;
dpr[i][0][0]=0;
}
for(int i=1;i<=n;i++){
for(int j=0;j<=i;j++){
for(int k=0;k<=i;k++){
if(j>0){
dpl[j][i-j][k]=min(dpl[j][i-j][k],min(dpr[j-1][i-j][k]+dis(n+1-(j),i-j),dpl[j-1][i-j][k]+dis(n+1-(j-1),n+1-(j))));
if(k>0&&(dpl[j-1][i-j][k-1]+dis(n+1-(j-1),n+1-j))<=t[n+1-j])dpl[j][i-j][k]=min(dpl[i][i-j][k],dpl[j-1][i-j][k-1]+dis(n+1-(j-1),n+1-j));
if(k>0&&(dpr[j-1][i-j][k-1]+dis(i-j,n+1-j))<=t[n+1-j])dpl[j][i-j][k]=min(dpl[i][i-j][k],dpr[j-1][i-j][k-1]+dis(i-j,n+1-j));
}
if(i-j>0){
dpr[j][i-j][k]=min(dpr[j][i-j][k],min(dpr[j][i-j-1][k]+dis(i-j-1,i-j),dpl[j][i-j-1][k]+dis(i-j,n+1-(j))));
if(k>0&&(dpr[j][i-j-1][k-1]+dis(i-j,i-j-1))<=t[i-j])dpr[j][i-j][k]=min(dpr[i][i-j][k],dpr[j][i-j-1][k-1]+dis(i-j,i-j-1));
if(k>0&&(dpl[j][i-j-1][k-1]+dis(i-j,n+1-j))<=t[i-j])dpr[j][i-j][k]=min(dpr[i][i-j][k],dpl[j][i-j-1][k-1]+dis(i-j,n+1-j));
}
}
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<=i;j++){
for(int k=0;k<=i;k++){
if(dpl[j][i-j][k]<maxn||dpr[j][i-j][k]<maxn){
ans=max(ans,k);
}
}
}
}
cout<<ans<<"\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
968 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
968 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Incorrect |
1 ms |
1096 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
968 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Incorrect |
82 ms |
108136 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
724 KB |
Output is correct |
4 |
Correct |
1 ms |
464 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
852 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
712 KB |
Output is correct |
9 |
Correct |
1 ms |
852 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
968 KB |
Output is correct |
13 |
Correct |
1 ms |
852 KB |
Output is correct |
14 |
Correct |
1 ms |
596 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
976 KB |
Output is correct |
17 |
Correct |
1 ms |
852 KB |
Output is correct |
18 |
Incorrect |
1 ms |
1096 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |