#include<bits/stdc++.h>
using namespace std;
#define task "a"
#define se second
#define fi first
#define ll long long
#define ii pair<ll, ll>
const long mxN = 2e2 + 7, inf = 1e9 + 7;
int n, dp[mxN][mxN][mxN][2], l;
ii a[mxN];
int dis(int u, int v)
{
return (v + l - u) % l;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
// freopen(task".INP", "r", stdin);
// freopen(task".OUT", "w", stdout);
cin >> n >> l;
for (int i = 1; i <= n; i++)
cin >> a[i].fi;
for (int i = 1; i <= n; i++)
cin >> a[i].se;
/*
dp[i][j][k][dir] = min time
phai la i
trai la j
ket qua la k
dir = 0 ben phai
dir = 1 ben trai
*/
for (int i = 0; i <= n; i++)
{
for (int j = i + 1; j <= n + 1; j++)
{
for (int k = 0; k <= n; k++)
{
for (int dir = 0; dir <= 1; dir++)
dp[i][j][k][dir] = inf;
}
}
}
int ans = 0;
dp[0][n + 1][0][0] = 0;
for (int i = 0; i <= n; i++)
{
for (int j = n + 1; j > i; j--)
{
for (int k = 0; k <= n; k++)
{
for (int dir = 0; dir <= 1; dir++)
{
if (dp[i][j][k][dir] == inf)
continue;
ans = max(ans, k);
int cur = a[i].fi;
if (dir)
cur = a[j].fi;
// den i + 1
int nw = dp[i][j][k][dir] + dis(cur, a[i + 1].fi);
dp[i + 1][j][k + (nw <= a[i + 1].se)][0] = min(dp[i + 1][j][k + (nw <= a[i + 1].se)][0], nw);
// den j - 1
nw = dp[i][j][k][dir] + dis(a[j - 1].fi, cur);
dp[i][j - 1][k + (nw <= a[j - 1].se)][1] = min(dp[i][j - 1][k + (nw <= a[j - 1].se)][1], nw);
}
}
}
}
cout << ans;
}
# | 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... |