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;
int N, L, X[205], T[205], D[205][205][205][2], ans;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N >> L;
for (int i = 1; i <= N; ++i) cin >> X[i];
for (int i = 1; i <= N; ++i) cin >> T[i];
for (int i = 0; i <= N; ++i)
for (int j = 1; j <= N + 1; ++j)
for (int k = 0; k <= N; ++k)
D[i][j][k][0] = D[i][j][k][1] = 1e9;
X[N + 1] = L;
D[0][N + 1][0][0] = D[0][N + 1][0][1] = 0;
for (int i = 0; i <= N; ++i) {
for (int j = N + 1; j > i; --j) {
for (int k = 0; k <= N; ++k) {
if (D[i][j][k][0] != 1e9 || D[i][j][k][1] != 1e9) ans = max(ans, k);
if (D[i][j][k][0] + X[i + 1] - X[i] <= T[i + 1]) D[i + 1][j][k + 1][0] = min(D[i + 1][j][k + 1][0], D[i][j][k][0] + X[i + 1] - X[i]);
else D[i + 1][j][k][0] = min(D[i + 1][j][k][0], D[i][j][k][0] + X[i + 1] - X[i]);
if (D[i][j][k][0] + X[i] + L - X[j - 1] <= T[j - 1]) D[i][j - 1][k + 1][1] = min(D[i][j - 1][k + 1][1], D[i][j][k][0] + X[i] + L - X[j - 1]);
else D[i][j - 1][k][1] = min(D[i][j - 1][k][1], D[i][j][k][0] + X[i] + L - X[j - 1]);
if (D[i][j][k][1] + X[j] - X[j - 1] <= T[j - 1]) D[i][j - 1][k + 1][1] = min(D[i][j - 1][k + 1][1], D[i][j][k][1] + X[j] - X[j - 1]);
else D[i][j - 1][k][1] = min(D[i][j - 1][k][1], D[i][j][k][1] + X[j] - X[j - 1]);
if (D[i][j][k][1] + L - X[j] + X[i + 1] <= T[i + 1]) D[i + 1][j][k + 1][0] = min(D[i + 1][j][k + 1][0], D[i][j][k][1] + L - X[j] + X[i + 1]);
else D[i + 1][j][k][0] = min(D[i + 1][j][k][0], D[i][j][k][1] + L - X[j] + X[i + 1]);
}
}
}
cout << ans;
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... |