#include <bits/stdc++.h>
using namespace std;
int main()
{
int N, L;
cin >> N >> L;
vector<pair<int, int>> Tab(N);
for (int i = 0; i < N; i++)
cin >> Tab[i].first;
for (int i = 0; i < N; i++)
cin >> Tab[i].second;
sort(Tab.begin(), Tab.end());
vector<vector<vector<vector<int>>>> dp(N, vector<vector<vector<int>>>(N, vector<vector<int>>(N + 1, vector<int>(2, 1234567890))));
int maxx = 0;
dp[0][0][(Tab[0].first <= Tab[0].second) ? 1 : 0][0] = Tab[0].first;
dp[N - 1][N - 1][(L - Tab[N - 1].first <= Tab[N - 1].second) ? 1 : 0][1] = L - Tab[N - 1].first;
for (int i = 0; i < N; i++)
{
for (int left = 0; left < N; left++)
{
int right = (left + N - i) % N;
for (int nb = 0; nb <= N; nb++)
{
if (min(dp[left][right][nb][0], dp[left][right][nb][1]) == 1234567890)
continue;
maxx = max(maxx, nb);
int next = (left + 1) % N, dist = (Tab[left].first < Tab[next].first) ? Tab[next].first - Tab[left].first : Tab[next].first + L - Tab[left].first;
dp[next][right][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][0] = min(dp[left][right][nb][0] + dist, dp[next][right][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][0]);
next = (left + 1) % N, dist = (Tab[right].first < Tab[next].first) ? Tab[next].first - Tab[right].first : Tab[next].first + L - Tab[right].first;
dp[next][right][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][0] = min(dp[left][right][nb][1] + dist, dp[next][right][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][0]);
next = (right - 1 + N) % N, dist = (Tab[right].first > Tab[next].first) ? Tab[right].first - Tab[next].first : Tab[right].first + L - Tab[next].first;
dp[left][next][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][1] = min(dp[left][right][nb][1] + dist, dp[left][next][(dp[left][right][nb][1] + dist > Tab[next].second) ? nb : nb + 1][1]);
next = (right - 1 + N) % N, dist = (Tab[left].first > Tab[next].first) ? Tab[left].first - Tab[next].first : Tab[left].first + L - Tab[next].first;
dp[left][next][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][1] = min(dp[left][right][nb][0] + dist, dp[left][next][(dp[left][right][nb][0] + dist > Tab[next].second) ? nb : nb + 1][1]);
}
}
}
cout << maxx;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
18 |
Halted |
0 ms |
0 KB |
- |