#GD0000079. Bao phủ một đoạn (Interval Cover)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Bao phủ một đoạn (Interval Cover)
Interval Cover
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Given a target real interval , where , and closed real intervals indexed from , select as few of them as possible so their union covers all of . Selected intervals may extend beyond the target. Output impossible if covering is infeasible; otherwise output an optimal count and the original zero-based indices. Any optimal selection is acceptable.
Input
The first line contains real numbers . The second line contains . Each of the next lines contains real numbers , written as decimals.
Output
Print impossible if no cover exists. Otherwise print the minimum number of intervals, followed by distinct zero-based interval indices in any order.
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
0 10
4
-1 4
3 8
8 12
2 6
Output
3
0 1 2
Explanation
Intervals , , and cover , then , then , so they cover . No pair can both cover the target start and reach its end. Thus three is optimal.