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 <iostream>
using namespace std;
#define MAXN 205
int n, l;
int dist[MAXN];
long long tm[MAXN];
long long dp[MAXN][MAXN][2][MAXN];
int o = 0;
int main () {
cin >> n >> l;
for (int i=1; i<=n; i++) {
cin >> dist[i];
}
dist[n+1] = l;
for (int i=1; i<=n; i++) {
cin >> tm[i];
}
tm[0] = tm[n+1] = -1;
for (int i=0; i<=n+1; i++) {
for (int j=0; j<=n+1; j++) {
for (int k=0; k<=n+1; k++) {
dp[i][j][0][k] = dp[i][j][1][k] = 1e16;
}
}
}
dp[0][n+1][0][0] = dp[0][n+1][1][0] = 0;
for (int i=0; i<=n+1; i++) {
for (int j=n+1; j>i+1; j--) {
for (int k=0; k<=n+1; k++) {
if (dp[i][j][0][k]+dist[i+1]-dist[i] <= tm[i+1]) {
dp[i+1][j][0][k+1] = min(dp[i+1][j][0][k+1], dp[i][j][0][k]+dist[i+1]-dist[i]);
} else {
dp[i+1][j][0][k] = min(dp[i+1][j][0][k], dp[i][j][0][k]+dist[i+1]-dist[i]);
}
if (dp[i][j][1][k]+dist[i+1]+l-dist[j] <= tm[i+1]) {
dp[i+1][j][0][k+1] = min(dp[i+1][j][0][k+1], dp[i][j][1][k]+dist[i+1]-dist[i]);
} else {
dp[i+1][j][0][k] = min(dp[i+1][j][0][k], dp[i][j][1][k]+dist[i+1]-dist[i]);
}
if (dp[i][j][1][k]+dist[j]-dist[j-1] <= tm[j-1]) {
dp[i][j-1][1][k+1] = min(dp[i][j-1][1][k+1], dp[i][j][1][k]+dist[j]-dist[j-1]);
} else {
dp[i][j-1][1][k] = min(dp[i][j-1][1][k], dp[i][j][1][k]+dist[j]-dist[j-1]);
}
if (dp[i][j][0][k]+dist[i]+l-dist[j-1] <= tm[j-1]) {
dp[i][j-1][1][k+1] = min(dp[i][j-1][1][k+1], dp[i][j][0][k]+dist[i]+l-dist[j-1]);
} else {
dp[i][j-1][1][k] = min(dp[i][j-1][1][k], dp[i][j][0][k]+dist[i]+l-dist[j-1]);
}
}
}
}
for (int i=0; i<=n+1; i++) {
for (int j=0; j<=n+1; j++) {
for (int k=0; k<=n+1; k++) {
if (dp[i][j][0][k] < 1e16 || dp[i][j][1][k] < 1e16) {
o = max(o, k);
}
}
}
}
cout << o << 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... |