#GD0000080. Bao phủ tối thiểu (Minimal Coverage)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bao phủ tối thiểu (Minimal Coverage)
Minimal Coverage
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You are given a positive integer and closed integer-endpoint segments . Choose the smallest number whose union covers the entire continuous interval . Segments may extend outside the target. Output 0 if covering is impossible; otherwise give the minimum count and the coordinates of selected segments in ascending left-end order. Multiple optimum covers may exist.
Input
The first line contains . Each of the next lines contains segment endpoints .
Output
Print 0 if no cover exists. Otherwise output the minimum number , followed by selected pairs in nondecreasing left-end order.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
10 4
-1 4
3 8
8 12
5 9
Output
3
-1 4
3 8
8 12
Explanation
Choose , , and . Their union covers . No pair among the four input segments covers the whole target, so three is optimal.