#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 210, inf = 1e15;
int dp[N][N][N][2], X[N], T[N];
int32_t main()
{
int n, L; 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 + 1; i++) for (int j = 0; j <= n + 1; j++) for (int c = 0; c <= n; c++) dp[i][j][c][0] = dp[i][j][c][1] = inf;
T[0] = T[n+1] = -1;
X[n+1] = L;
dp[0][n+1][0][0] = dp[0][n+1][0][1] = 0;
int ans = 0;
for (int c = 0; c <= n; c++) {
for (int i = 0; i <= n; i++) {
for (int j = n + 1; j >= 1; j--) {
if (i > 0) {
dp[i][j][c][0] = min(dp[i - 1][j][c][0] + X[i] - X[i - 1], dp[i - 1][j][c][1] + X[i] + L - X[j]);
if (c > 0 && dp[i - 1][j][c - 1][0] + X[i] - X[i - 1] <= T[i])
dp[i][j][c][0] = min(dp[i][j][c][0], dp[i - 1][j][c - 1][0] + X[i] - X[i - 1]);
if (c > 0 && dp[i - 1][j][c - 1][1] + X[i] + L - X[j] <= T[i])
dp[i][j][c][0] = min(dp[i][j][c][0], dp[i - 1][j][c - 1][1] + X[i] + L - X[j]);
}
if (j < n + 1) {
dp[i][j][c][1] = min(dp[i][j + 1][c][1] + X[j + 1] - X[j], dp[i][j + 1][c][0] + X[i] + L - X[j]);
if (c > 0 && dp[i][j + 1][c - 1][1] + X[j + 1] - X[j] <= T[j])
dp[i][j][c][1] = min(dp[i][j][c][1], dp[i][j + 1][c - 1][1] + X[j + 1] - X[j]);
if (c > 0 && dp[i][j + 1][c - 1][0] + X[i] + X[j] <= T[j])
dp[i][j][c][1] = min(dp[i][j][c][1], dp[i][j + 1][c - 1][0] + X[i] + L - X[j]);
}
if (dp[i][j][c][0] < inf) ans = c;
if (dp[i][j][c][1] < inf) ans = c;
}
}
}
cout << ans << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
504 KB |
Output is correct |
2 |
Incorrect |
5 ms |
508 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |