#P9288. [ROI 2018] Innophone

[ROI 2018] Innophone

Background

Translated from ROI 2018 Day1 T3. Иннофон (Innophone)。

Problem Description

There is a binary function f(x,y)f(x,y) defined as follows:

$f(x,y)=\left\{ \begin{array}{rcl} a, & & {\text{if} \quad \quad \ \ \ a \leq x}\\ b, & & {\text{else if} \quad b \leq y}\\ 0, & & {\text{else}} \end{array} \right.$

Here a,ba,b are constants. You are given nn pairs (x,y)(x,y). You need to choose suitable a,ba,b so that i=1nf(xi,yi)\sum_{i=1}^{n} f(x_i,y_i) is maximized.

Input Format

The first line contains an integer nn, the number of pairs (x,y)(x,y).

The next nn lines each contain two numbers xix_i and yiy_i.

Output Format

Output one number on one line: max(i=1nf(xi,yi))\max(\sum_{i=1}^{n} f(x_i,y_i)).

5
80 20
60 50
40 40
15 10
70 30
220
1
50 0
50

Hint

For 100%100\% of the testdata, 0yixi1090\leq y_i\leq x_i\leq 10^9, 1n1.5×1051 \leq n \leq 1.5 \times 10^5.

Subtask ID nn x,yx,y
11 1n1001 \leq n \leq 100 0yixi1000 \leq y_i \leq x_i \leq 100
22 1n3001 \leq n \leq 300 0yixi1090\leq y_i\leq x_i\leq 10^9
33 1n30001 \leq n \leq 3000
44 1n1051 \leq n \leq 10^5 yi=0y_i = 0
55 xi=yix_i = y_i
66 1n500001 \leq n \leq 50000 0yixi1090\leq y_i\leq x_i\leq 10^9
77 1n750001 \leq n \leq 75000
88 1n1051 \leq n \leq 10^5
99 1n1.25×1051 \leq n \leq 1.25 \times 10^5
1010 1n1.5×1051 \leq n \leq 1.5 \times 10^5

Translated by ChatGPT 5