This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
void dout() { cerr << '\n'; }
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << " " << H;
    dout(T...);
}
#ifdef LOCAL
    #define dbg(...) cerr << #__VA_ARGS__, dout(__VA_ARGS__)
#else
    #define dbg(...) ;
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
const int N = 203;
ll n, l, x[N], t[N];
ll dp[2][N][N][N];
void upd(ll & x, ll y) {
    x = min(x, y);
}
int main() {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    cin >> n >> l;
    for (int i = 1; i <= n; i++) {
        cin >> x[i];
    }
    for (int i = 1; i <= n; i++) {
        cin >> t[i];
    }
    memset(& dp, 0x3f, sizeof(dp));
    ll inf = dp[0][0][0][0];
    dp[0][0][0][0] = dp[1][0][0][0] = 0;
    int res = 0;
    for (int i = 0; i <= n; i++) {
        for (int j = 0; i + j <= n; j++) {
            for (int k = 0; k <= n; k++) {
                if (dp[0][i][j][k] < inf) {
                    if (i < n) {
                        ll val = dp[0][i][j][k] + min(x[i + 1] - x[i], l - (x[i + 1] - x[i]));
                        upd(dp[0][i + 1][j][k + (t[i + 1] >= val)], val);
                    }
                    if (j < n) {
                        ll d = abs(x[n - j] - x[i]);
                        ll val = dp[0][i][j][k] + min(d, l - d);
                        upd(dp[1][i][j + 1][k + (t[n - j] >= val)], val);
                    }
                    res = max(res, k);
                }
                if (dp[1][i][j][k] < inf) {
                    if (i < n) {
                        ll d = abs(x[i + 1] - x[(n - j + 1) % (n + 1)]);
                        ll val = dp[1][i][j][k] + min(d, l - d);
                        upd(dp[0][i + 1][j][k + (t[i + 1] >= val)], val);
                    }
                    if (j < n) {
                        ll d = abs(x[n - j] - x[(n - j + 1) % (n + 1)]);
                        ll val = dp[1][i][j][k] + min(d, l - d);
                        upd(dp[1][i][j + 1][k + (t[n - j] >= val)], val);
                    }
                    res = max(res, k);
                }
            }
        }
    }
    cout << res;
}
| # | 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... |