#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define all(x) x.begin(), x.end()
#define int long long
#define pq priority_queue
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pp pop_back
#define F first
#define S second
using namespace std;
int n, m, k, ans;
int a[205], t[205];
int dp[205][205][2][205];
int calc(int l, int r, int p, int c) {
if (c == 0) return 1e14;
if (l > r) return -1e14;
if (dp[l][r][p][c] != -1) return dp[l][r][p][c];
int k = (!p ? l - 1 : r + 1);
int ans = -1e14;
int r1 = calc(l+1, r, 0, c) - min(abs(a[l] - a[k]), m - abs(a[l] - a[k]));
int r2 = calc(l, r-1, 1, c) - min(abs(a[r] - a[k]), m - abs(a[r] - a[k]));
int r3 = min(t[l], calc(l+1, r, 0, c-1)) - min(abs(a[l]-a[k]), m - abs(a[l]-a[k]));
int r4 = min(t[r], calc(l, r-1, 1, c-1)) - min(abs(a[r]-a[k]), m - abs(a[r]-a[k]));
ans = max({ans, r1, r2, r3, r4});
dp[l][r][p][c] = ans;
return ans;
}
void solve () {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[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++) if (calc(0, n-1, 1, i) >= 0) ans = i;
cout << ans;
}
signed main() {IOS solve(); 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... |