P9288 [ROI 2018] Innophone

题目背景

译自 [ROI 2018 Day1](https://neerc.ifmo.ru/school/archive/2017-2018.html) T3. [Иннофон](https://neerc.ifmo.ru/school/archive/2017-2018/ru-olymp-roi-2018-day1.pdf) ([Innophone](http://codeforces.com/gym/102147/problem/B))。

题目描述

有一个二元函数 $f(x,y)$,它是这么定义的: $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.$ 其中 $a,b$ 为常数。现在给定 $n$ 组 $x,y$,你需要选择合适的 $a,b$,使得 $\sum_{i=1}^{n} f(x_i,y_i)$ 最大。

输入格式

第一行一个整数 $n$,表示 $x$,$y$ 的组数。 后面 $n$ 行,每行两个数 $x_i$,$y_i$。

输出格式

一行,一个数,输出 $\max(\sum_{i=1}^{n} f(x_i,y_i))$。

说明/提示

对于 $100\%$ 的数据,$0\leq y_i\leq x_i\leq 10^9$,$1 \leq n \leq 1.5 \times 10^5$。 | 子任务编号 | $n$ | $x,y$ | | :----------: | :----------: | :----------: | | $1$ | $1 \leq n \leq 100$ | $0 \leq y_i \leq x_i \leq 100$ | | $2$ | $1 \leq n \leq 300$ | $0\leq y_i\leq x_i\leq 10^9$ | | $3$ | $1 \leq n \leq 3000$ | $0\leq y_i\leq x_i\leq 10^9$ | | $4$ | $1 \leq n \leq 10^5$ | $y_i = 0$ | | $5$ | $1 \leq n \leq 10^5$ | $x_i = y_i$ | | $6$ | $1 \leq n \leq 50000$ | $0\leq y_i\leq x_i\leq 10^9$ | | $7$ | $1 \leq n \leq 75000$ | $0\leq y_i\leq x_i\leq 10^9$ | | $8$ | $1 \leq n \leq 10^5$ | $0\leq y_i\leq x_i\leq 10^9$ | | $9$ | $1 \leq n \leq 1.25 \times 10^5$ | $0\leq y_i\leq x_i\leq 10^9$ | | $10$ | $1 \leq n \leq 1.5 \times 10^5$ | $0\leq y_i\leq x_i\leq 10^9$ |