#include <bits/stdc++.h>
//ako ovaj vaso daso misli da me pobedjuje.....
using namespace std;
#define int long long
#define f first
#define s second
const int N = 210;
const int inf = 1e18;
int n, l, x[N], t[N], dp[N][N][2][2];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
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 = 0;j <= n;j++)
dp[i][j][0][0] = dp[i][j][1][0] = inf;
}
//3-i/j
//4-time/skor
dp[0][0][0][0] = dp[0][0][1][0] = 0;
int ans = 0;
for (int i = 0;i <= n;i++) {
for (int j = 0;j <= n;j++) {
if (i + j > n)
break;
for (int k = i - 1;k >= 0;k--) {
int time = dp[k][j][0][0] + abs(x[i] - x[k]);
if (time <= t[i]) {
if (dp[i][j][0][1] < dp[k][j][0][1] + 1) {
dp[i][j][0][1] = dp[k][j][0][1] + 1;
dp[i][j][0][0] = time;
}
else if (dp[i][j][0][1] == dp[k][j][0][1] + 1)
dp[i][j][0][0] = min(dp[i][j][0][0], time);
}
time = dp[k][j][0][0] + x[i] + (l - x[k]);
if (time <= t[i]) {
if (dp[i][j][0][1] < dp[k][j][1][1] + 1) {
dp[i][j][0][1] = dp[k][j][1][1] + 1;
dp[i][j][0][0] = time;
}
else if (dp[i][j][0][1] == dp[k][j][1][1] + 1)
dp[i][j][0][0] = min(dp[i][j][0][0], time);
}
}
for (int k = j - 1;k >= 0;k--) {
int time = dp[i][k][1][0] + abs(x[n - j + 1] - x[n - k + 1]);
if (time <= t[n - j + 1]) {
if (dp[i][j][1][1] < dp[i][k][1][1] + 1) {
dp[i][j][1][1] = dp[i][k][1][1] + 1;
dp[i][j][1][0] = time;
}
else if (dp[i][j][1][1] == dp[i][k][1][1] + 1)
dp[i][j][1][0] = min(dp[i][j][1][0], time);
}
time = dp[i][k][0][0] + x[i] + (l - x[n - j + 1]);
if (time <= t[n - j + 1]) {
if (dp[i][j][1][1] < dp[i][k][0][1] + 1) {
dp[i][j][1][1] = dp[i][k][0][1] + 1;
dp[i][j][1][0] = time;
}
else if (dp[i][j][1][1] == dp[i][k][0][1] + 1)
dp[i][j][1][0] = min(dp[i][j][1][0], time);
}
}
ans = max(ans, max(dp[i][j][0][1], dp[i][j][1][1]));
}
}
cout << ans;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
468 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |