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>
#include <map>
using namespace std;
using ll = long long;
int n, l;
ll x[205], t[205];
map<ll, int> dp[205][205];
ll dist(int x1, int x2) {
if (x1 > x2) swap(x1, x2);
return min(x2 - x1, l - x2 + x1);
}
int solve(int i, int j, int time_passed) {
if (abs(i - j) == 1) return 0;
if (dp[i][j].count(time_passed)) return dp[i][j][time_passed];
int cur = i, l = min(i, j), r = max(i, j);
int ans = solve(l + 1, r, dist(x[cur], x[l + 1]) + time_passed) + (dist(x[cur], x[l + 1]) + time_passed <= t[l + 1]);
ans = max(ans, solve(r - 1, l, dist(x[cur], x[r - 1]) + time_passed) + (dist(x[cur], x[r - 1]) + time_passed <= t[r - 1]));
dp[i][j][time_passed] = ans;
return ans;
}
int main() {
cin >> n >> l;
for (int i = 1; i <= n; i++) {
cin >> x[i];
}
for (int i = 1; i <= n; i++) {
cin >> t[i];
}
t[0] = t[n + 1] = 0;
cout << solve(0, n + 1, 0) << '\n';
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... |