P6879 [JOI 2020 Final] Stamp Collecting Contest 3 / Collecting Stamps 3
Description
Given a circle with circumference $L$, starting from a point, there are $N$ black-and-white bear statues numbered from $1$ to $N$. The $i$-th statue is located $X_i$ meters clockwise from the starting point. If you do not collect this black-and-white bear statue within $T_i$ seconds, it will make a “wuppuppuppu” sound and then explode.
Now JOI-kun is at the starting point. He can move $1$ meter per second, and he may move either clockwise or counterclockwise.
JOI-kun wants to know: what is the maximum number of black-and-white bear statues he can collect?
Input Format
The first line contains two integers $N, L$, representing the number of statues and the circumference of the circle.
The second line contains $N$ integers $X_i$, representing how many meters clockwise each statue is located from the starting point.
The third line contains $N$ integers $T_i$, representing within how many seconds each statue must be collected.
Output Format
Output one integer on a single line, representing the answer.
Explanation/Hint
#### Explanation for Sample 1
JOI-kun can collect $4$ black-and-white bear statues using the following strategy:
|Direction|Distance|Total Time|Which Statue|Can Collect|
|:-:|:-:|:-:|:-:|:-:|
|Counterclockwise|$2$ meters|$2$ seconds|$6$|$\sqrt{}$|
|Counterclockwise|$2$ meters|$4$ seconds|$5$|$\sqrt{}$|
|Clockwise|$7$ meters|$11$ seconds|$1$|$\sqrt{}$|
|Clockwise|$1$ meter|$12$ seconds|$2$|$\times$|
|Clockwise|$3$ meters|$15$ seconds|$3$|$\sqrt{}$|
#### Explanation for Sample 2
JOI-kun can just keep walking counterclockwise.
#### Explanation for Sample 3
JOI-kun cannot obtain any statue.
#### Constraints
**This problem uses bundled testdata.**
- Subtask 1 (5 pts): $N \le 12$, $L \le 200$, $X_i \le 200$.
- Subtask 2 (10 pts): $N \le 15$.
- Subtask 3 (10 pts): $L \le 200$, $T_i \le 200$.
- Subtask 4 (75 pts): No special restrictions.
For $100\%$ of the testdata:
- $1 \le N \le 200$.
- $2 \le L \le 10^9$.
- $1 \le X_i < L$.
- $X_i < X_{i+1}$.
- $0 \le T_i \le 10^9$.
#### Notes
Translated from [The 19th Japanese Olympiad in Informatics, Final Round](https://www.ioi-jp.org/joi/2019/2020-ho/index.html) [C Stamp Rally 3](https://www.ioi-jp.org/joi/2019/2020-ho/2020-ho-t3.pdf).
Translated by ChatGPT 5