#C13326. Merge Overlapping Intervals
Merge Overlapping Intervals
Merge Overlapping Intervals
You are given a list of intervals. Each interval is represented by two integers a and b (with a < b) forming the interval \([a, b]\). Your task is to merge all overlapping or adjacent intervals and output the merged intervals in sorted order.
Note: Two intervals \([a, b]\) and \([c, d]\) are considered overlapping or adjacent if \(c \le b\). The merged interval will then be \([a, \max(b, d)]\).
The input is read from stdin and the output should be written to stdout.
inputFormat
The first line contains an integer n representing the number of intervals. Each of the following n lines contains two space-separated integers a and b, representing the start and end of an interval \([a, b]\).
outputFormat
Output the merged intervals, one interval per line. Each line should contain two space-separated integers representing the start and end of the merged interval. The merged intervals must be sorted by their start times.
## sample1
1 2
1 2
</p>