#include "bits/stdc++.h"
using namespace std;
#ifdef duc_debug
#include "bits/debug.h"
#else
#define debug(...)
#endif
const int maxn = 205;
int n, l;
int x[maxn], t[maxn];
long long f[maxn][maxn][maxn][2];
void solve() {
cin >> n >> l;
for(int i = 1; i <= n; ++i) {
cin >> x[i];
}
for(int i = 1; i <= n; ++i) {
cin >> t[i];
}
x[n + 1] = l;
memset(f, 0x3f, sizeof(f));
f[0][n + 1][0][0] = f[0][n + 1][0][1] = 0;
for(int i = 0; i <= n; ++i) {
for(int j = n + 1; j > i; --j) {
for(int score = 0; score <= (i + (n - j + 1)); ++score) {
if(f[i][j][score][1] < 1e18) {
if(j - 1 > i) {
long long time = f[i][j][score][1] + (x[j] - x[j - 1]);
int add = (time <= t[j - 1]);
f[i][j - 1][score + add][1] = min(f[i][j - 1][score + add][1], time);
}
if(i + 1 < j) {
long long time = f[i][j][score][1] + (l - x[j] + x[i + 1]);
int add = (time <= t[i + 1]);
f[i + 1][j][score + add][0] = min(f[i + 1][j][score + add][0], time);
}
}
if(f[i][j][score][0] < 1e18) {
if(j - 1 > i) {
long long time = f[i][j][score][0] + (x[i] + l - x[j - 1]);
int add = (time <= t[j - 1]);
f[i][j - 1][score + add][1] = min(f[i][j - 1][score + add][1], time);
}
if(i + 1 < j) {
long long time = f[i][j][score][0] + (x[i + 1] - x[i]);
int add = (time <= t[i + 1]);
f[i + 1][j][score + add][0] = min(f[i + 1][j][score + add][0], time);
}
}
// debug(i, j, score, f[i][j][score][0], f[i][j][score][1]);
}
}
}
int res = 0;
for(int i = 0; i <= n; ++i) {
for(int j = n + 1; j > i; --j) {
for(int score = 0; score <= n; ++score) {
for(int at = 0; at < 2; ++at) {
if(f[i][j][score][at] < 1e18) {
if(res < score) {
res = score;
}
}
}
}
}
}
cout << res;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | 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... |