#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC optimize("Ofast,unroll-loops,inline-functions,no-stack-protector,03")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,avx2,mmx,fma,avx,tune=native")
#pragma clang loop vectorize(enable)
#pragma clang loop interleave(enable)
#endif
#define int long long
#define sz(x) (int)x.size()
#define F first
#define S second
#define pb push_back
#define nl '\n'
#define o_set tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int, int> pii;
void file( string s = "" )
{
if( s.empty() )
return;
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const int N = 2e5 + 2;
const int N1 = 1e6 + 2;
const int inf = 1e9 + 2;
const int INF = 1e18 + 2;
const int mod = 1e9 + 7;
int T = 1, n, l, x[203], t[203], dp[203][203][203][2];
void solve()
{
cin >>n >>l;
for( int i = 1; i <= n; ++i )
cin >>x[i];
x[n + 1] = l;
for( int i = 1; i <= n; ++i )
cin >>t[i];
for( int i = 0; i <= n + 1; ++i )
for( int j = 0; j <= n + 1; ++j )
for( int k = 0; k <= n + 1; ++k )
dp[i][j][k][0] = dp[i][j][k][1] = INF;
int ans = 0;
dp[0][n + 1][0][0] = dp[0][n + 1][0][1] = 0;
for( int i = 0; i < n; ++i )
for( int j = n + 1; j - 1 > i; --j )
for( int k = 0, kk; k <= n; ++k )
{
if( dp[i][j][k][0] >= INF && dp[i][j][k][1] >= INF )
continue;
if( dp[i][j][k][0] != INF )
{
kk = k + (dp[i][j][k][0] + x[i + 1] - x[i] <= t[i + 1]);
ans = max(ans, kk);
dp[i + 1][j][kk][0] = min(dp[i + 1][j][kk][0], dp[i][j][k][0] + x[i + 1] - x[i]);
kk = k + (dp[i][j][k][0] + x[i] + l - x[j - 1] <= t[j - 1]);
ans = max(ans, kk);
dp[i][j - 1][kk][1] = min(dp[i][j - 1][kk][1], dp[i][j][k][0] + x[i] + l - x[j - 1]);
}
if( dp[i][j][k][1] != INF )
{
kk = k + (dp[i][j][k][1] + l - x[j] + x[i + 1] <= t[i + 1]);
ans = max(ans, kk);
dp[i + 1][j][kk][0] = min(dp[i + 1][j][kk][0], dp[i][j][k][1] + l - x[j] + x[i + 1]);
kk = k + (dp[i][j][k][1] + x[j] - x[j - 1] <= t[j - 1]);
ans = max(ans, kk);
dp[i][j - 1][kk][1] = min(dp[i][j - 1][kk][1], dp[i][j][k][1] + x[j] - x[j - 1]);
}
}
cout <<ans;
}
signed main()
{
file("");
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// cin >>T;
while( T-- )
solve();
}
Compilation message (stderr)
ho_t3.cpp: In function 'void file(std::string)':
ho_t3.cpp:29:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ho_t3.cpp:30:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | freopen((s + ".out").c_str(), "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... |