QOJ.ac

QOJ

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

#13068. Intervals

统计

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
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.