#K2131. Merge Intervals
Merge Intervals
Merge Intervals
You are given a list of intervals. Each interval is represented by two integers where the first integer is the start and the second is the end. Your task is to merge all overlapping intervals and output the resulting non-overlapping intervals in sorted order.
Two intervals [a, b] and [c, d] are considered overlapping if \(b \ge c\). The merging process combines them into a new interval \([a, \max(b, d)]\). This problem tests your ability to correctly sort and merge overlapping intervals.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer \(n\) representing the number of intervals.
- Each of the next \(n\) lines contains two space-separated integers \(a\) and \(b\) representing the start and end of an interval.
outputFormat
The output is written to standard output (stdout) and should have the following format:
- The first line contains an integer \(m\) denoting the number of merged intervals.
- Each of the next \(m\) lines contains two space-separated integers representing a merged interval.
0
0