#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();
}
}
vector<vector<unordered_map<ll, ll>>> dp1(401, vector<unordered_map<ll, ll>>(2));
vector<vector<unordered_map<ll, ll>>> dp2(401, vector<unordered_map<ll, ll>>(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);
}
dp1[n][0][0] = 0;
ll ans = 0;
for (int len = 1; len <= n + 1; len++) {
for (int l = 0; l + len <= 2 * n + 1; l++) {
ll r = l + len - 1;
for (auto [time, cnt] : dp1[l][0]) {
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++;
}
dp2[l - 1][0][nw_time] = max(dp2[l - 1][0][nw_time], cost);
nw_time = time + pref[r + 1] - pref[l];
cost = cnt;
if (nw_time <= a[r + 1]) {
cost++;
}
dp2[l][1][nw_time] = max(dp2[l][1][nw_time], cost);
}
for (auto [time, cnt] : dp1[l][1]) {
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++;
}
dp2[l - 1][0][nw_time] = max(dp2[l - 1][0][nw_time], cost);
nw_time = time + b[r];
cost = cnt;
if (nw_time <= a[r + 1]) {
cost++;
}
dp2[l][1][nw_time] = max(dp2[l][1][nw_time], cost);
}
dp2[l][0].clear();
dp2[l][1].clear();
}
dp1 = dp2;
}
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... |