P16238 [Lanqiao Cup 2026 NOI Qualifier B] Ideal Temperature
Description
On an industrial production line, there are $n$ temperature sensors arranged in order. The current temperatures measured by the sensors are recorded in array $A$, and the corresponding ideal target temperatures are recorded in array $B$ (that is, $A_i$ is the current temperature of the $i$-th sensor, and $B_i$ is the ideal temperature of the $i$-th sensor).
To make as many sensors as possible reach the ideal temperature, you may perform one range temperature compensation operation:
1. Choose a continuous interval of sensors $[l, r]$ on the line (i.e., the $l$-th to the $r$-th sensors).
2. Input a compensation value $k$ ($k$ can be any integer), so that the current temperature of every sensor in this interval is increased by $k$.
After performing this single calibration operation, what is the maximum number of sensors whose temperatures can be exactly equal to their corresponding ideal target temperatures?
Input Format
The first line contains an integer $n$, representing the number of sensors.
The second line contains $n$ integers $A_1, A_2, \dots, A_n$, representing the current temperatures of the sensors.
The third line contains $n$ integers $B_1, B_2, \dots, B_n$, representing the ideal target temperatures of the sensors.
Output Format
Output one line containing an integer, representing the maximum number of sensors that are at the ideal temperature after the compensation operation.
Explanation/Hint
### Constraints
For $30\%$ of the testdata, it is guaranteed that $1 \le n \le 2000$.
For all testdata, it is guaranteed that $1 \le n \le 2 \times 10^5$, $-10^9 \le A_i, B_i \le 10^9$.
Translated by ChatGPT 5