PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000256. Hợp các khoảng (Union of Interval)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Hợp các khoảng (Union of Interval)
Union of Interval
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given half-open real intervals , each consisting of real with , express their union using the fewest half-open intervals. Adjacent intervals may be merged.
Input
First line: . The next lines contain .
Output
Print each resulting pair on its own line in ascending order of . Do not print the number of intervals.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; .
Example 1
Input
3
10 20
20 30
40 50
Output
10 30
40 50
Explanation
The first two are adjacent and merge into [10,30); the last is separate.
Example 2
Input
3
10 40
30 60
20 50
Output
10 60
Explanation
All three overlap into [10,60).