#C13558. Merge Intervals with Target Integration
Merge Intervals with Target Integration
Merge Intervals with Target Integration
You are given a list of intervals and a target interval. Each interval is represented as a list of two integers [start, end] satisfying \(start < end\). Your task is to merge all overlapping intervals including the target interval, and then output the final set of disjoint intervals in sorted order.
Two intervals \([a, b]\) and \([c, d]\) are considered overlapping if \(b \ge c\). The target interval should be merged with any intervals it overlaps with. If there is no overlap, simply add the target interval to the list.
Note: The final list of intervals must be printed in increasing order of their start value, each interval printed on a new line with its two endpoints separated by a space.
inputFormat
The first line contains an integer \(n\) representing the number of intervals.
The next \(n\) lines each contain two integers separated by a space representing the start and end of each interval.
The last line contains two integers separated by a space representing the target interval.
outputFormat
Output the merged intervals, one interval per line. Each line should contain two integers separated by a space representing the start and end of an interval.
## sample3
1 3
5 7
8 12
4 6
1 3
4 7
8 12
</p>