This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |