QOJ.ac

QOJ

时间限制: 1.0 s 内存限制: 32 MB 总分: 80

#17118. 礼物

统计

Mirko 收到了一组区间作为他的生日礼物。他可以用它们玩很多游戏。在其中一个游戏中,Mirko 需要找出由互不相同的区间组成的最长序列,使得序列中的每个区间都属于给定的集合,且序列中的每个区间都包含其后紧邻的区间。

请编写一个程序,找出这样一个最长序列。

输入格式

第一行包含一个整数 $N$ ($1 \le N \le 100\,000$),表示集合中区间的数量。

接下来的 $N$ 行,每行包含两个整数 $A$ 和 $B$ ($1 \le A < B \le 1\,000\,000$),描述一个区间。

输出格式

第一行输出最长序列的长度 $K$。

接下来的 $K$ 行,每行输出序列中的一个区间,格式与输入格式相同。

样例

输入样例 1

3
3 4
2 5
1 6

输出样例 1

3
1 6
2 5
3 4

输入样例 2

5
10 30
20 40
30 50
10 60
30 40

输出样例 2

3
10 60
30 50
30 40

输入样例 3

6
1 4
1 5
1 6
1 7
2 5
3 5

输出样例 3

5
1 7
1 6
1 5
2 5
3 5

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.