#P10705. Peak Maximization and Range Optimization
Peak Maximization and Range Optimization
Peak Maximization and Range Optimization
Given two arrays (a) and (b) of length (n), you are to construct a sequence (S) of length (n) such that for each index (i) ((1 \le i \le n)) the element (S_i) is chosen to be either (a_i) or (b_i). In addition, define (S_0 = S_{n+1} = 0). An element (S_i) (for (1 \le i \le n)) is called a (\textbf{peak}) if it satisfies the condition (S_i > S_{i-1}) and (S_i > S_{i+1}).
The goal is to construct (S) so that:
- The number of peaks is maximized.
- Among all sequences achieving the maximum number of peaks, the extreme range is maximized. The (\textbf{extreme range}) is defined as the difference between the maximum and minimum values among (S_1, S_2, \ldots, S_n) (i.e. excluding (S_0) and (S_{n+1})).
Formally, if the maximum number of peaks is (P_{max}) and among all sequences that have (P_{max}) peaks, the maximum extreme range is (R_{max}), then you must output (P_{max}) and (R_{max}).
inputFormat
The first line contains an integer \(n\)
(e.g. number of positions in the sequence).
The second line contains \(n\) integers \(a_1, a_2, \ldots, a_n\).
The third line contains \(n\) integers \(b_1, b_2, \ldots, b_n\).
outputFormat
Output two integers separated by a space: the maximum number of peaks and the maximum extreme range among sequences that achieve this peak count.
sample
3
1 3 2
2 2 3
1 2