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 N 205
#define int long long
using namespace std;
int x[2*N],t[2*N];
int dp[2*N][2*N][N][2];
int L;
int go(int a,int b,int dir){
if(dir == 0){
return (x[a] - x[b] + L)%L;
}
return (x[b] - x[a] +L)%L;
}
void solve(){
for(int i=0;i<2*N;i++){
for(int j=0;j<2*N;j++){
for(int c=0;c<N;c++){
for(int d=0;d<2;d++){
dp[i][j][c][d] = 2e18;
}
}
}
}
int n;
cin >> n >> L;
n++;
dp[n+1][n+1][0][0] = 0;
for(int i=2;i<=n;i++){
cin >> x[i];
}
for(int i=2;i<=n;i++){
cin >> t[i];
}
for(int i=n+1;i<=2*n;i++){
x[i] = x[i-n];
t[i] = t[i-n];
}
for(int len=2;len<=n;len++){
for(int l=1;l<=n+1;l++){
int r = l+len-2;
for(int c=0;c<=n;c++){
dp[l-1][r][c + (dp[l][r][c][0] + go(l,l-1,0) <= t[l-1])][0] = min(dp[l-1][r][c + (dp[l][r][c][0] + go(l,l-1,0) <= t[l-1])][0], dp[l][r][c][0] + go(l,l-1,0));
dp[l][r+1][c + (dp[l][r][c][0] + go(l,r+1,1) <= t[r+1])][1] = min(dp[l][r+1][c + (dp[l][r][c][0] + go(l,r+1,1) <= t[r+1])][1], dp[l][r][c][0] + go(l,r+1,1));
dp[l-1][r][c + (dp[l][r][c][1] + go(r,l-1,0) <= t[l-1])][0] = min(dp[l-1][r][c + (dp[l][r][c][1] + go(r,l-1,0) <= t[l-1])][0], dp[l][r][c][1] + go(r,l-1,0));
dp[l][r+1][c + (dp[l][r][c][1] + go(r,r+1,1) <= t[r+1])][1] = min(dp[l][r+1][c + (dp[l][r][c][1] + go(r,r+1,1) <= t[r+1])][1], dp[l][r][c][1] + go(r,r+1,1));
}
}
}
int ans = 0;
for(int i=0;i<2*N;i++){
for(int j=0;j<2*N;j++){
for(int c=0;c<N;c++){
for(int d=0;d<2;d++){
if(dp[i][j][c][d] != 2e18)ans = max(ans,c);
}
}
}
}
cout << ans;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef Local
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t=1;
//cin>>t;
while(t--){
solve();
}
#ifdef Local
cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
#endif
}
# | 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... |