This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define sz(x) (int)x.size()
#define all(x) x.begin(),x.end()
#define pb emplace_back
#define X first
#define Y second
const int N = 205;
int x[N];
int t[N];
ll f[N][N][N][2];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n; cin >> n;
int L; cin >> L;
for(int i = 1 ; i <= n ; ++i) cin >> x[i];
for(int i = 1 ; i <= n ; ++i) cin >> t[i];
for(int i = 1 ; i <= n ; ++i)
f[0][0][i][0] = 2e18,
f[0][0][i][1] = 2e18;
x[n + 1] = L;
for(int i = 0 ; i <= n ; ++i)
for(int j = 0 ; j <= n ; ++j) {
if (i < 1 && j < 1) continue;
if (i + j > n) break;
for(int k = 0 ; k <= n ; ++k) {
ll& res1 = f[i][j][k][0]; res1 = 2e18;
ll& res2 = f[i][j][k][1]; res2 = 2e18;
if (i)
res1 = min(res1,f[i - 1][j][k][0] + x[n - i + 2] - x[n - i + 1]),
res1 = min(res1,f[i - 1][j][k][1] + x[j] + L - x[n - i + 1]);
if (j)
res2 = min(res2,f[i][j - 1][k][0] + x[j] + L - x[n - i + 1]),
res2 = min(res2,f[i][j - 1][k][1] + x[j] - x[j - 1]);
if (k == 0) continue;
ll nxt;
if (i) {
if ((nxt = f[i - 1][j][k - 1][0] + x[n - i + 2] - x[n - i + 1]) <= t[n - i + 1]) res1 = min(res1,nxt);
if ((nxt = f[i - 1][j][k - 1][1] + x[j] + L - x[n - i + 1]) <= t[n - i + 1]) res1 = min(res1,nxt);
}
if (j) {
if ((nxt = f[i][j - 1][k - 1][0] + x[j] + L - x[n - i + 1]) <= t[j]) res2 = min(res2,nxt);
if ((nxt = f[i][j - 1][k - 1][1] + x[j] - x[j - 1]) <= t[j]) res2 = min(res2,nxt);
}
}
}
int ans = 0;
for(int i = 0 ; i <= n ; ++i)
for(int k = 0 ; k <= n ; ++k) {
if (f[i][n - i][k][0] < 2e18) ans = max(ans,k);
if (f[i][n - i][k][1] < 2e18) ans = max(ans,k);
}
cout << ans << endl;
}
# | 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... |