1339. Intervals

单点时限: 2.0 sec

内存限制: 256 MB

There is given the series of $n$ closed intervals $[a_i; b_i]$, where $i=1,2,\ldots,n$. The sum of those intervals may be represented as a sum of closed pairwise non-intersecting intervals. The task is to find such representation with the minimal number of intervals. The intervals of this representation should be written in the output file in acceding order. We say that the intervals $[a; b]$ and $[c; d]$ are in ascending order if, and only if $a \le b < c \le d$.

Write a program which:

  1. reads the description of the series of intervals,
  2. computes pairwise non-intersecting intervals satisfying the conditions given above,
  3. writes the computed intervals in ascending order.

输入格式

In the first line there is one integer $n$, $3 \le n \le 50~000$. This is the number of intervals. In the $(i+1)$-st line, $1 \le i \le n$, there is a description of the interval $[a_i; b_i]$ in the form of two integers $a_i$ and $b_i$ separated by a single space, which are respectively the beginning and the end of the interval, $1 \le ai \le bi \le 1~000~000$.

输出格式

The out should contain descriptions of all computed pairwise non-intersecting intervals. In each line should be written a description of one interval. It should be composed of two integers, separated by a single space, the beginning and the end of the interval respectively. The intervals should be written into the output file in ascending order.

样例

Input
5
5 6
1 4
10 10
6 9
8 10
Output
1 4
5 10

11 人解决,18 人已尝试。

13 份提交通过,共有 41 份提交。

6.2 EMB 奖励。

创建: 17 年,3 月前.

修改: 7 年,1 月前.

最后提交: 1 周,2 天前.

来源: POI 2001 I Stage

题目标签