QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 256 MB Total points: 100

#13068. Intervals

Statistics

Let interval $[s, t]$ denote the set of integers between $s$ and $t$, inclusively. Given a set of $n$ intervals $A = \{[s_i, t_i]\}$, compute a set of intervals $B$ (not necessary a subset of $A$), such that each $[s_i, t_i] \in A$ can be presented as the union (set-union) of some intervals in $B$. The goal is to minimize the number of intervals in $B$.

Input

There are at most $100$ test cases. Each case will consist of one integer $n$, following $n$ lines each consists of $s_i$ and $t_i$, separated by a space.

$1 \leq n \leq 1000$, $0 \leq s_i \leq t_i \leq 10^9$.

Output

For each test case, print a single line containing one integer $m$, the number of intervals. The $j$-th line of the following $m$ lines contain the $j$-th interval as $s_j$ and $t_j$, the intervals can be in any order. If there are multiple solutions with the same number of intervals, any of them will be accepted.

Sample Input

2
1 2
3 4
3
1 2
3 4
1 4
7
5 9
0 6
4 8
3 7
0 5
7 9
4 6

Sample Output

2
1 2
3 4
2
1 2
3 4
5
0 5
4 6
3 7
5 8
7 9

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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. Submitting multiple issues may cause your account to be banned.
  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.