#K32772. Compress Page Ranges
Compress Page Ranges
Compress Page Ranges
You are given a list of page ranges. Your task is to merge all overlapping or consecutive ranges into a single range. A page range is represented as a pair of integers [start, end] where start and end are the first and last page numbers of the range, respectively.
Formally, given a set of ranges \([a_i, b_i]\) sorted by \(a_i\), if \(b_i \geq a_{i+1} - 1\) then these ranges should be merged into \([a_i, \max(b_i, b_{i+1})]\). Continue this process until no more ranges can be merged.
inputFormat
The input is read from standard input (stdin). The first line contains an integer \(N\) denoting the number of page ranges. Each of the next \(N\) lines contains two space-separated integers representing the start and end of a page range.
outputFormat
Output the merged page ranges to standard output (stdout). For each merged range, print a line containing two space-separated integers denoting the start and end of that range. The ranges should be printed in ascending order.
## sample4
15 18
1 4
11 14
17 20
1 4
11 20
</p>