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>
using namespace std;
typedef long long ll;
int n,L;
ll x[201], t[201];
ll dp[201][201][2][201];
int dist(int i, int j) {
return min(abs(x[i]-x[j]), L-abs(x[i]-x[j]));
}
//mikor elég legkésőbb kezdeni
ll solve(int l, int r, int side, int cnt) {
if(cnt==0) return 1LL<<60;
if(l>r) {
return -1LL<<60;
}
//cerr<<l<<" "<<r<<" "<<side<<" "<<cnt<<"\n";
if(dp[l][r][side][cnt]!=-1) return dp[l][r][side][cnt];
int akt;
if(side==0) akt=l-1;
else akt=r+1;
ll ans=-1LL<<60;
ans=max(ans, solve(l+1,r,0,cnt)-dist(l,akt));
ans=max(ans, min(t[l],solve(l+1,r,0,cnt-1))-dist(l,akt));
ans=max(ans, solve(l,r-1,1,cnt)-dist(r,akt));
ans=max(ans, min(t[r], solve(l,r-1,1,cnt-1))-dist(r,akt));
return dp[l][r][side][cnt]=ans;
}
int main() {
cin>>n>>L;
for(int i=0;i<n;++i) cin>>x[i];
for(int i=0;i<n;++i) cin>>t[i];
memset(dp,-1,sizeof dp);
int ans=0;
for(int i=0;i<=n;i++) {
//cerr<<i<<": "<<solve(0,n-1,1,i)<<"\n";
if(solve(0,n-1,1,i)>=0) ans=i;
}
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... |