#C510. Merging Meeting Intervals

    ID: 48712 Type: Default 1000ms 256MiB

Merging Meeting Intervals

Merging Meeting Intervals

You are given a list of meeting intervals. Each interval is represented by a pair of integers (start, end) where the start and end denote the beginning and ending times of a meeting, respectively. Two meetings overlap if the start time of one is less than or equal to the end time of another. Your task is to merge all overlapping intervals and output the consolidated meeting intervals. For instance, intervals [1, 3] and [2, 5] overlap because (3 \ge 2), and they should be merged into [1, 5].

Solve this problem for multiple test cases in an efficient manner.

inputFormat

The input begins with an integer (T) denoting the number of test cases. Each test case starts with an integer (N) representing the number of meetings. This is followed by (N) lines, each containing two space-separated integers that represent the start and end times of a meeting.

outputFormat

For each test case, output a single line with the merged meeting intervals. Each interval is printed as two space-separated integers (start and end). If there are multiple intervals, separate them by a space. In case there are no meetings, output an empty line.## sample

3
1 3
2 4
5 7
1 4 5 7