#C5852. Merge Overlapping Time Slots

    ID: 49547 Type: Default 1000ms 256MiB

Merge Overlapping Time Slots

Merge Overlapping Time Slots

You are given a list of time slots represented by their start and end times in 24-hour format. Your task is to merge all overlapping time slots and output the merged intervals sorted by their start times.

Formally, given a list of intervals \( [s_i, e_i] \) for \( i=1,2,\ldots,n \), if two intervals \( [s_i, e_i] \) and \( [s_j, e_j] \) overlap (i.e. if \( s_j \le e_i \)), merge them into a single interval \( [s_i, \max(e_i, e_j)] \). Continue this process until no more intervals can be merged.

For example, merging \( [9, 11] \) and \( [10, 12] \) will result in \( [9, 12] \).

inputFormat

The first line of input contains an integer \( n \), representing the number of time slots. Each of the next \( n \) lines contains two integers representing the start and end times of a time slot.

Input Format:

n
s1 e1
s2 e2
... 
sn en

outputFormat

Output the merged time slots, each on a new line. Each line should contain two integers (the start and end time) separated by a space.

## sample
3
9 11
13 16
18 20
9 11

13 16 18 20

</p>