luogu#P10705. 孤独(Solitude)

孤独(Solitude)

Background

Yearsofwalkingpassinquietpeace,Years of walking pass in quiet peace, Undertheancientdarkbluesky.Under the ancient dark-blue sky. SoftlyIbegintosing,Softly I begin to sing, Ofthatwindbird.Of that wind bird. Butyouarenowheretobeseen.But you are nowhere to be seen.

Problem Description

You are given nn, and nn integers aia_i (1in1\le i\le n), and nn integers bib_i (1in1\le i\le n).

Now, for a sequence SS of length nn, the following rules apply:

  • Si=aiS_i = a_i or bib_i.

  • For all SiS_i (1in1\le i\le n), if Si>Si1S_i > S_{i-1} and Si>Si+1S_i > S_{i+1}, then SiS_i is called a peak. In particular, S0=Sn+1=0S_0 = S_{n+1} = 0.

You need to find: the maximum number of peaks, and the maximum range when the number of peaks is maximized.

Range: the difference between the maximum value and the minimum value in a sequence.

Updated: S0S_0 and Sn+1S_{n+1} do not participate in the range calculation.

Input Format

The first line contains an integer nn.

The second line contains nn integers, representing a1,a2ana_1, a_2 \dots a_n.

The third line contains nn integers, representing b1,b2bnb_1, b_2 \dots b_n.

Output Format

Output two lines in total.

The first line contains an integer representing the maximum number of peaks.

The second line contains an integer representing the maximum range when the maximum number of peaks is achieved.

6
9 1 2 4 7 10 
8 10 5 1 1 7 
3
9
10
6 13 27 31 34 59 64 66 71 95 
4 4 10 22 26 28 46 55 62 68 
5
91

Hint

Sample Explanation

In Sample 1, one valid sequence SS is 9,1,2,4,1,109,1,2,4,1,10.

Among them, S1,S4,S6S_1, S_4, S_6 are peaks, and the range is 101=910-1=9.

Constraints

Subtask ID nn Special Property Score
00 20\le 20 - 1010
11 2000\le 2000
22 105\le 10^5 AA
33 BB
44 CC
55 5×105\le 5\times10^5 - 5050

Special property AA: 1<in\forall 1< i\le n, max(ai1,bi1)min(ai,bi)\text{max}(a_{i-1},b_{i-1})\le \text{min}(a_i,b_i).

Special property BB: 1<in\forall 1< i\le n, $\text{min}(a_i,b_i)\le\text{max}(a_{i-1},b_{i-1})\le\text{max}(a_i,b_i)$.

Special property CC: 1in\forall 1\le i\le n, ai=ka_i = k, where kk is a positive integer.

For 100%100\% of the testdata, 1n5×1051\le n\le 5\times10^5, 1ai,bi1091\le a_i,b_i\le 10^9, and it is guaranteed that aibia_i\ne b_i.

Special reminder: This problem uses bundled subtask testing. You only get the score of a subtask if you pass all test points in that subtask.

Translated by ChatGPT 5