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>
using namespace std;
const int N = 212, MOD = 1e9 + 7;
typedef long long ll;
#define int ll
int n,L,t[N],x[N];
pair<int,ll> dp[N][N][2];
void test() {
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++){
for(int k =0 ;k < 2;k++){
dp[i][j][k] = {-1e18,-1e18};
}
}
}
dp[0][0][0] = dp[0][0][1] = {0,0};
x[n + 1] = L;
for(int i =0;i <=n;i++)
{
for(int j = 0;j <= n;j++){
if(i + j >= n) break;
{
dp[i + 1][j][0] = max(dp[i + 1][j][0], make_pair(
dp[i][j][0].first + (-dp[i][j][0].second + x[i + 1] - x[i] <= t[i + 1]),
dp[i][j][0].second - x[i + 1] + x[i]));
dp[i + 1][j][0] = max(dp[i + 1][j][0], make_pair(
dp[i][j][1].first + (-dp[i][j][1].second + L - x[n - j + 1] + x[i + 1] <= t[i + 1]),
dp[i][j][1].second - (L - x[n - j + 1] + x[i + 1])));
dp[i + 1][j][1] = max(dp[i + 1][j][1], make_pair(dp[i + 1][j][0].first, dp[i + 1][j][0].second -
(x[i + 1] + L - x[n - j + 1])));
}
{
dp[i][j + 1][1] = max({dp[i][j + 1][1], make_pair(
dp[i][j][1].first + (-dp[i][j][1].second + x[n - j + 1] - x[n - j] <= t[n - j]),
(dp[i][j][1].second - (x[n - j + 1] - x[n - j])))});
dp[i][j + 1][1] = max({dp[i][j + 1][1], make_pair(
dp[i][j][0].first + (-dp[i][j][0].second + x[i] + L - x[n - j] <= t[n - j]),
dp[i][j][0].second - (x[i] + L - x[n - j]))});
dp[i][j + 1][0] = max(dp[i][j + 1][0], make_pair(dp[i][j + 1][1].first,
dp[i][j + 1][1].second - (x[i] + L - x[n - j])));
}
}
}
int res = 0;
for(int i = 0;i <= n;i++){
for(int j = 0;j <= n;j++){
if(i + j <= n) res = max({res,dp[i][j][0].first,dp[i][j][1].first});
}
}
cout << res << '\n';
}
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int T = 1;
// cin >> T;
while (T--)
test();
}
# | 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... |