#include <bits/stdc++.h>
using namespace std;
#define TASK "long"
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define GETBIT(mask, i) ((mask) >> (i) & 1)
#define MASK(i) ((1LL) << (i))
#define SZ(x) ((int)(x).size())
#define mp make_pair
#define CNTBIT(mask) __builtin_popcount(mask)
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y) {x = y; return true;} return false;};
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y) {x = y; return true;} return false;};
typedef pair<int, int> ii;
const int N = 200 + 5;
const int inf = 1e9 + 7;
const long long INF = (long long)1e18 + 7;
const int mod = 1e9 + 7;
void add(int &x, int y) {x += y; if (x >= mod) x -= mod;}
void sub(int &x, int y) {x -= y; if (x < 0) x += mod;}
int mul(int x, int y) {return 1LL * x * y % mod;}
// -----------------------------------------//
int n, L;
int x[N], timer[N];
void read() {
cin >> n >> L;
for(int i = 1; i <= n; i++) cin >> x[i];
for(int i = 1; i <= n; i++) cin >> timer[i];
}
void sub3() {
vector<vector<int>> dp;
// dp.assign(n + 2, vector<int>(202, -inf));
// dp[0][0] = 0;
// for(int i = 1; i <= n; i++) {
// for(int t = 1; t <= 200; t++) {
// dp[i][t] = dp[i - 1]
// }
// }
}
pair<int, int> dp[N][N][2];
pair<int, int> merge(const ii &x, const ii &y) {
if (x.fi > y.fi) return x;
if (x.fi < y.fi) return y;
return min(x, y);
}
void solve() {
for(int i = 0; i <= n + 1; i++) {
for(int j = 0; j <= n + 1; j++) {
for(int k: {0, 1}) {
dp[i][j][k] = {0, inf};
}
}
}
x[n + 1] = L;
// dp[0][0][0] = dp[0][0][1] = {0, 0};
dp[0][n + 1][0] = dp[0][n + 1][1] = {0, 0};
for(int i = 1; i <= n; i++) {
dp[i][n + 1][0] = {dp[i - 1][n + 1][0].fi + (dp[i - 1][n + 1][0].se + x[i] - x[i - 1] <= timer[i]), dp[i - 1][n + 1][0].se + x[i] - x[i - 1]};
}
for(int i = n; i >= 1; i--) {
dp[0][i][1] = {dp[0][i + 1][1].fi + (dp[0][i + 1][1].se + x[i + 1] - x[i] <= timer[i]), dp[0][i + 1][1].se + x[i + 1] - x[i]};
}
for(int i = 1; i <= n; i++) {
for(int j = n; j >= i; j--) {
// dp[i][j][0] = dp[i][j][1] = {0, inf};
if (dp[i - 1][j][0].se + x[i] - x[i - 1] <= timer[i]) {
dp[i][j][0] = merge(dp[i][j][0], mp(dp[i - 1][j][0].fi + 1, dp[i - 1][j][0].se + x[i] - x[i - 1]));
}
else dp[i][j][0] = merge(dp[i][j][0], mp(dp[i - 1][j][0].fi, dp[i - 1][j][0].se + x[i] - x[i - 1]));
if (dp[i - 1][j][1].se + L - x[j] + x[i] <= timer[i]) {
dp[i][j][0] = merge(dp[i][j][0], mp(dp[i - 1][j][1].fi + 1, dp[i - 1][j][1].se + L - x[j] + x[i]));
}
else dp[i][j][0] = merge(dp[i][j][0], mp(dp[i - 1][j][0].fi, dp[i - 1][j][1].se + L - x[j] + x[i]));
// 1
if (dp[i][j + 1][1].se + x[j + 1] - x[j] <= timer[j]) {
dp[i][j][1] = merge(dp[i][j][1], mp(dp[i][j + 1][1].fi + 1, dp[i][j + 1][1].se + x[j + 1] - x[j]));
}
else dp[i][j][1] = merge(dp[i][j][1], mp(dp[i][j + 1][1].fi, dp[i][j + 1][1].se + x[j + 1] - x[j]));
if (dp[i][j + 1][0].se + x[i] + L - x[j] <= timer[j]) {
dp[i][j][1] = merge(dp[i][j][1], mp(dp[i][j + 1][0].fi + 1, dp[i][j + 1][0].se + x[i] + L - x[j]));
}
else dp[i][j][1] = merge(dp[i][j][1], mp(dp[i][j + 1][0].fi, dp[i][j + 1][0].se + x[i] + L - x[j]));
}
}
int ans = 0;
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
for(int k: {0, 1}) ans = max(ans, dp[i][j][k].fi);
}
}
cout << ans;
}
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if (fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
int test = 1;
// cin >> test;
while(test--) {
read();
solve();
}
return 0;
}
Compilation message (stderr)
ho_t3.cpp: In function 'int main()':
ho_t3.cpp:98:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
98 | freopen(TASK".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:99:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
99 | freopen(TASK".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |