#C9522. Merge Intervals
Merge Intervals
Merge Intervals
You are given a collection of intervals, each represented by a pair of integers. Your task is to merge all overlapping intervals and output a list of non-overlapping intervals sorted by their starting point.
Two intervals \( [a, b] \) and \( [c, d] \) overlap if \( c \le b \). When they overlap, they should be merged into \( [\min(a, c), \max(b, d)] \). For instance, merging \( [1, 3] \) and \( [2, 4] \) produces \( [1, 4] \).
Please note that the input is provided via standard input (stdin) and the output should be written to standard output (stdout), where each interval is printed on a new line.
inputFormat
The input begins with an integer \( n \) (\( n \ge 0 \)) representing the number of intervals. The following \( n \) lines each contain two space-separated integers, \( start \) and \( end \), representing an interval.
outputFormat
Output the merged intervals. Each merged interval should be printed on its own line with the start and end values separated by a space. If there are no intervals, output nothing.
## sample4
1 3
2 4
5 7
6 8
1 4
5 8
</p>