#P16238. [蓝桥杯 2026 省 B] 理想温度

    ID: 18272 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP前缀和2026蓝桥杯省赛

[蓝桥杯 2026 省 B] 理想温度

Problem Description

On an industrial production line, there are nn temperature sensors arranged in order. The current temperatures measured by the sensors are recorded in array AA, and the corresponding ideal target temperatures are recorded in array BB (that is, AiA_i is the current temperature of the ii-th sensor, and BiB_i is the ideal temperature of the ii-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][l, r] on the line (i.e., the ll-th to the rr-th sensors).
  2. Input a compensation value kk (kk can be any integer), so that the current temperature of every sensor in this interval is increased by kk.

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 nn, representing the number of sensors.

The second line contains nn integers A1,A2,,AnA_1, A_2, \dots, A_n, representing the current temperatures of the sensors.

The third line contains nn integers B1,B2,,BnB_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.

5
1 2 3 4 5
2 3 2 3 2
2

Hint

Constraints

For 30%30\% of the testdata, it is guaranteed that 1n20001 \le n \le 2000.

For all testdata, it is guaranteed that 1n2×1051 \le n \le 2 \times 10^5, 109Ai,Bi109-10^9 \le A_i, B_i \le 10^9.

Translated by ChatGPT 5