#include <bits/stdc++.h>
#include <experimental/random>
#include <random>
using namespace std;
using ll = long long;
using ld = long double;
const ll INF = 1e18, MOD = 998244353;
void solve();
signed main() {
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll q = 1;
//cin >> q;
while (q--) {
solve();
}
}
ll dp[202][201][201][2];
void solve() {
ll n, all;
cin >> n >> all;
vector<ll> x(n);
ll prev = 0;
for (int i = 0; i < n; i++) {
ll t;
cin >> t;
x[i] = t - prev;
prev = t;
}
vector<ll> t(n);
for (int i = 0; i < n; i++) {
cin >> t[i];
}
vector<ll> a;
for (int i = 0; i < n; i++) {
a.push_back(t[i]);
}
a.push_back(INF);
for (int i = 0; i < n; i++) {
a.push_back(t[i]);
}
vector<ll> b;
for (int i = 1; i < n; i++) {
b.push_back(x[i]);
}
b.push_back(all - prev);
for (int i = 0; i < n; i++) {
b.push_back(x[i]);
}
vector<ll> pref = {0};
for (auto i : b) {
pref.push_back(pref.back() + i);
}
for (int i = 0; i <= n + 1; i++) {
for (int l = 0; l <= n; l++) {
for (int cnt = 0; cnt <= n; cnt++) {
dp[i][l][cnt][0] = INF;
dp[i][l][cnt][1] = INF;
}
}
}
dp[1][n][0][0] = 0;
ll ans = 0;
for (int len = 1; len <= n + 1; len++) {
for (int l = 0; l <= n; l++) {
ll r = l + len - 1;
for (ll cnt = 0; cnt <= n; cnt++) {
ll time = dp[len][l][cnt][0];
if (time != INF) {
ans = max(ans, cnt);
}
if (len == n + 1) {
continue;
}
ll nw_time = time + b[l - 1];
ll cost = cnt;
if (nw_time <= a[l - 1]) {
cost++;
}
dp[len + 1][l - 1][cost][0] = min(dp[len + 1][l - 1][cost][0], nw_time);
nw_time = time + pref[r + 1] - pref[l];
cost = cnt;
if (nw_time <= a[r + 1]) {
cost++;
}
dp[len + 1][l][cost][1] = min(dp[len + 1][l][cost][1], nw_time);
}
for (ll cnt = 0; cnt <= n; cnt++) {
ll time = dp[len][l][cnt][1];
if (time != INF) {
ans = max(ans, cnt);
}
if (len == n + 1) {
continue;
}
ll nw_time = time + pref[r] - pref[l - 1];
ll cost = cnt;
if (nw_time <= a[l - 1]) {
cost++;
}
dp[len + 1][l - 1][cost][0] = min(dp[len + 1][l - 1][cost][0], nw_time);
nw_time = time + b[r];
cost = cnt;
if (nw_time <= a[r + 1]) {
cost++;
}
dp[len + 1][l][cost][1] = min(dp[len + 1][l][cost][1], nw_time);
}
}
}
cout << ans;
}
# | 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... |