#P1702. Maximal Consecutive Desks Test
Maximal Consecutive Desks Test
Maximal Consecutive Desks Test
In this problem, a teacher conducts a pop quiz based on students' exam ability levels. There are (N) desk rows arranged in a line, and each desk row seats two students with ability levels (A_i) and (B_i) for the (i)-th row. The teacher intends to give a test to students with ability level (K). To do so, he will select (L) consecutive rows such that each row in the selected segment has at least one student whose ability level equals (K). Your task is to determine the maximum possible (L) (i.e. the maximum number of consecutive rows meeting the condition) and the corresponding ability level (K) which achieves this maximum. In the case of a tie (i.e. several ability levels produce the same maximum (L)), output the smallest (K).
inputFormat
The input begins with a single integer (N) (the number of desk rows). Each of the following (N) lines contains two integers (A_i) and (B_i) separated by a space, representing the ability levels of the two students at that desk.
outputFormat
Output two integers separated by a space: the maximum possible (L) and the corresponding ability level (K). If multiple ability levels yield the same maximum (L), output the smallest (K).
sample
6
1 2
2 3
1 2
2 2
1 3
2 1
4 2