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;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
const bool typetest = 0;
const int N = 2e2 + 5;
const ll Inf = 1e17;
int n;
ll x[N], y[N], t[N];
ll dp[N][N][N][2], l;
int ans(0);
void Read()
{
cin >> n >> l;
t[0] = -1;
for (int i = 1; i <= n; ++i)
{
cin >> x[i];
y[i] = l - x[i];
}
for (int i = 1; i <= n; ++i)
cin >> t[i];
}
int pos(int v)
{
v += n + 1;
if (v >= n + 1)
v -= n + 1;
if (v >= n + 1)
v -= n + 1;
return v;
}
template <class T>
inline void Min(T &x, T y)
{
if (x > y)
x = y;
}
void Solve()
{
fill_n(&dp[0][0][0][0], N * N * N * 2, Inf);
dp[0][0][0][0] = dp[0][0][0][1] = 0;
for (int i = 0; i <= n; ++i)
for (int j = 0; j <= n; ++j)
for (int h = 0; h <= i; ++h)
{
if (dp[j][pos(j + i)][h][0] != Inf)
{
ans = max(ans, h);
ll v = dp[j][pos(j + i)][h][0] + y[pos(j - 1)] - y[j];
Min(dp[pos(j - 1)][pos(j + i)][h + (v <= t[pos(j - 1)])][0], v);
v = dp[j][pos(j + i)][h][0] + y[j] + x[pos(j + i + 1)];
Min(dp[j][pos(j + i + 1)][h + (v <= t[pos(j + i + 1)])][1], v);
}
if (dp[j][(j + i) % (n + 1)][h][1] != Inf)
{
ans = max(ans, h);
ll v = dp[j][pos(j + i)][h][1] + x[pos(j + i + 1)] - x[pos(j + i)];
Min(dp[j][pos(j + i + 1)][h + (v <= t[pos(j + i + 1)])][1], v);
v = dp[j][pos(j + i)][h][1] + x[pos(j + i)] + y[pos(j - 1)];
Min(dp[pos(j - 1)][pos(j + i)][h + (v <= t[pos(j - 1)])][0], v);
}
}
cout << ans;
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t(1);
if (typetest)
cin >> t;
for (int _ = 1; _ <= t; ++_)
{
Read();
Solve();
}
}
# | 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... |