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>
//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][1][0] + x[i] + (l - x[n - j + 1]);
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] - (k == 0 ? l - x[n - k + 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);
}
}
if (i == 0 && j > 0)
dp[i][j][0][0] = 2 * (l - x[n - j + 1]);
if (j == 0 && i > 0)
dp[i][j][1][0] = 2 * x[i];
ans = max(ans, max(dp[i][j][0][1], dp[i][j][1][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... |