#abc360f. F - InterSections

F - InterSections

Score : 550550 points

问题陈述

给定 NN 个编号为 11NN 的区间。区间 ii[Li,Ri][L_i, R_i]

如果两个区间 [la,ra][l_a, r_a][lb,rb][l_b, r_b] 满足以下条件之一,则它们被认为相交(la<lb<ra<rb)(l_a < l_b < r_a < r_b)(lb<la<rb<ra)(l_b < l_a < r_b < r_a)

定义 f(l,r)f(l, r) 为与区间 [l,r][l, r] 相交的区间 ii 的数量(1iN1 \leq i \leq N)。

在所有满足 0l<r1090 \leq l < r \leq 10^{9}整数(l,r)(l, r) 中,找到使 f(l,r)f(l, r) 最大化的对 (l,r)(l, r)。如果有多个这样的对,选择 ll 最小的对。如果还有多个对,选择它们中 rr 最小的对。(由于 0l<r0 \leq l < r,要回答的对 (l,r)(l, r) 是唯一确定的。)

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

You are given NN intervals numbered 11 to NN. Interval ii is [Li,Ri][L_i, R_i].

Two intervals [la,ra][l_a, r_a] and [lb,rb][l_b, r_b] are said to intersect if and only if they satisfy either (la<lb<ra<rb)(l_a < l_b < r_a < r_b) or (lb<la<rb<ra)(l_b < l_a < r_b < r_a).

Define f(l,r)f(l, r) as the number of intervals ii (1iN1 \leq i \leq N) that intersect with the interval [l,r][l, r].

Among all pairs of integers (l,r)(l, r) satisfying 0l<r1090 \leq l < r \leq 10^{9}, find the pair (l,r)(l, r) that maximizes f(l,r)f(l, r). If there are multiple such pairs, choose the one with the smallest ll. If there are still multiple pairs, choose the one with the smallest rr among them. (Since 0l<r0 \leq l < r, the pair (l,r)(l, r) to be answered is uniquely determined.)

Constraints

  • 1N1051 \leq N \leq 10^{5}
  • 0Li<Ri1090 \leq L_i < R_i \leq 10^{9} (1iN)(1 \leq i \leq N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

L1L_1 R1R_1

L2L_2 R2R_2

\vdots

LNL_N RNR_N

Output

Print the sought pair (l,r)(l, r) in the following format:

ll rr

Sample Input 1

5
1 7
3 9
7 18
10 14
15 20

Sample Output 1

4 11

The maximum value of f(l,r)f(l, r) is 44, and among the pairs (l,r)(l, r) that achieve f(l,r)=4f(l, r) = 4, the smallest ll is 44. The pairs (l,r)(l, r) that satisfy f(l,r)=4f(l, r) = 4 and l=4l = 4 are the following five:

  • (l,r)=(4,11)(l, r) = (4, 11)
  • (l,r)=(4,12)(l, r) = (4, 12)
  • (l,r)=(4,13)(l, r) = (4, 13)
  • (l,r)=(4,16)(l, r) = (4, 16)
  • (l,r)=(4,17)(l, r) = (4, 17)

Among these, the smallest rr is 1111, so print 44 and 1111.

Sample Input 2

11
856977192 996441446
298251737 935869360
396653206 658841528
710569907 929136831
325371222 425309117
379628374 697340458
835681913 939343451
140179224 887672320
375607390 611397526
93530028 581033295
249611310 775998537

Sample Output 2

396653207 887672321