#include <bits/stdc++.h>
//#pragma GCC optimize("Ofast,O3,unroll-loops")
//#pragma GCC target("avx2")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define len(v) (int)((v).size())
const ll inf = 1e18;
inline void solve() {
int n, l;
cin >> n >> l;
vector<int> x(n + 1), t(n + 1);
for (int i = 1; i <= n; ++i){
cin >> x[i];
}
for (int i = 1; i <= n; ++i){
cin >> t[i];
}
x[0] = 0;
t[0] = -1;
vector<vector<vector<vector<ll>>>> dp(n + 1, vector<vector<vector<ll>>>(n + 1, vector<vector<ll>>(n + 1, vector<ll>(2, inf))));
dp[0][0][0][0] = 0;
auto dist = [&](int i, int j){
return min(abs(x[i] - x[j]), l - abs(x[i] - x[j]));
};
for (int ln = 1; ln <= n; ++ln){
for (int l = 0; l <= n; ++l){
int r = (l + ln - 1) % (n + 1);
for (int c = 0; c < n; ++c){
for (int f = 0; f < 2; ++f){
int ind = l * (!f) + r * f;
{
int nl = (l + n) % (n + 1);
ll nv = dp[l][r][c][f] + dist(nl, ind);
dp[nl][r][c + (nv <= t[nl])][0] = min(dp[nl][r][c + (nv <= t[nl])][0], nv);
}
{
int nr = (r + 1) % (n + 1);
ll nv = dp[l][r][c][f] + dist(nr, ind);
dp[l][nr][c + (nv <= t[nr])][1] = min(dp[l][nr][c + (nv <= t[nr])][1], nv);
}
}
}
}
}
int ans = 0;
for (int l = 0; l <= n; ++l){
for (int r = 0; r <= n; ++r){
for (int c = 0; c <= n; ++c){
for (int f = 0; f < 2; ++f){
if (dp[l][r][c][f] < inf){
ans = max(ans, c);
}
}
}
}
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
# | 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... |