QOJ.ac

QOJ

时间限制: 1 s 内存限制: 128 MB 总分: 10

#10640. 班卓琴 [B]

统计

有一天,Bajtazar 去 Bajtogród 的集市上弹奏班卓琴。为了不给周围的居民造成太大困扰,他决定只演奏两首时长各为一分钟的短曲。尽管如此,Bajtazar 还是希望尽可能多的人能听到他的演奏。于是他演奏了一首,等待了一会儿,然后又演奏了第二首。现在他想知道,是否有可能让更多的人听到他的表演。

一天之内,共有 $n$ 个人经过集市,我们将他们编号为 1 到 $n$。Bajtazar 准确地记住了每个人何时来到集市。第 $i$ 个人在第 $p_i$ 分钟初到达集市,并在第 $k_i$ 分钟初离开集市。

Bajtazar 想计算出,如果他在最佳时间开始演奏,最多能有多少人听到他的演奏。然而,这个问题超出了他的计算能力,因为 Bajtocja 的一天长达 $10^9$ 分钟。绝望的 Bajtazar 向你寻求帮助。

我们假设 Bajtazar 总共演奏两次,每次演奏一分钟。每场演出可以在任何时间开始。特别地,第二首歌可以在第一首歌结束后立即开始。如果一个人在 Bajtazar 演奏的那一整分钟内都在集市上,那么他就能听到演奏。

输入格式

输入的第一行包含一个整数 $n$ ($1 \le n \le 500\,000$),表示一天中来到集市的人数。接下来的 $n$ 行中,每一行描述一个人。第 $i$ 行包含两个整数 $p_i$ 和 $k_i$ ($1 \le p_i \le k_i \le 10^9$),表示第 $i$ 个人在第 $p_i$ 分钟初到达集市,在第 $k_i$ 分钟初离开集市。

输出格式

你的程序应该输出能够听到 Bajtazar 班卓琴演奏的最多不同人数。

样例

输入 1

7
3 6
1 16
9 13
4 6
7 9
1 1
9 10

输出 1

5

说明

Bajtazar 在第四分钟的任意时刻或第五分钟初开始第一首歌。因此,第 1、2 和 4 个人听到了第一首歌。Bajtazar 在第九分钟演奏第二首歌,此时第 2、3 和 7 个人在集市上。总共有 5 个不同的人听到了 Bajtazar 的演奏。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.