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;
#define TRACE(x) cerr << #x << " :: " << x << endl
#define _ << " " <<
#define SZ(x) (int)(x).size()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for (int i=(a);i>=(b);--i)
const int MX_N = 205;
const int MX_T = 1e9+5;
int N, L;
int X[MX_N], T[MX_N];
int atL[MX_N][MX_N][MX_N];
int atR[MX_N][MX_N][MX_N];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> L;
    FOR(i,1,N){
        cin >> X[i];
    }
    FOR(i,1,N){
        cin >> T[i];
    }
    X[0] = 0; X[N+1] = L;
    T[0] = T[N+1] = -1;
    //atL[N+1][0][0] = atR[N+1][0][0] = 0;
    FOR(l,1,N+1){
        FOR(r,0,l-1){
            atL[l][r][0] = min(1LL*MX_T, 2LL*X[r] + L-X[l]);
            atR[l][r][0] = min(1LL*MX_T, 2LL*(L-X[l]) + X[r]);
        }
    }
    int ans = 0;
    FOR(y,1,N){
        FOR(l,1,N+1){
            FOR(r,0,l-1){
                atL[l][r][y] = MX_T;
                FOR(k,l+1,N+1){
                    if (atL[k][r][y-1] + X[k]-X[l] <= T[l]) atL[l][r][y] = min(atL[l][r][y], atL[k][r][y-1] + X[k]-X[l]);
                    if (atR[k][r][y-1] + L-X[l]+X[r] <= T[l]) atL[l][r][y] = min(atL[l][r][y], atR[k][r][y-1] + L-X[l]+X[r]);
                }
                if (atL[l][r][y] < MX_T) ans = max(ans,y);
                atR[l][r][y] = MX_T;
                FOR(k,0,r-1){
                    if (atR[l][k][y-1] + X[r]-X[k] <= T[r]) atR[l][r][y] = min(atR[l][r][y], atR[l][k][y-1] + X[r]-X[k]);
                    if (atL[l][k][y-1] + X[r]+L-X[l] <= T[r]) atR[l][r][y] = min(atR[l][r][y], atL[l][k][y-1] + X[r]+L-X[l]);
                }
                if (atR[l][r][y] < MX_T) ans = max(ans,y);
                //TRACE(l _ r _ y _ atL[l][r][y] _ atR[l][r][y]);
                //cout << flush;
                //assert(atL[l][r][y] >= 0 && atR[l][r][y] >= 0);
            }
        }
    }
    cout << ans << '\n';
}
| # | 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... |