← 返回 meta 的题目列表Merge Two Sorted Interval Arrays
类型:online_judge
Problem
You are given two interval arrays A and B, each sorted by start. Each interval is a closed interval [l, r].
Merge the two lists and return the union of all intervals (merge any overlapping intervals). The output must be sorted by start.
Input
First line: m
Next m lines: l r for intervals in A
Next line: n
Next n lines: l r for intervals in B
Output
Print merged intervals, one per line as l r.
Constraints
0 <= m, n <= 2e5
-1e9 <= l <= r <= 1e9
Example
A = [[1,2],[3,4]], B = [[1,3],[7,8],[9,10]] => [[1,4],[7,8],[9,10]]
Example
Input
2
1 2
3 4
3
1 3
7 8
9 10
Output
1 4
7 8
9 10