PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#LCA0000022. Phủ một đoạn bằng ít đoạn nhất (Minimal Segment Cover)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phủ một đoạn bằng ít đoạn nhất (Minimal Segment Cover)
Minimal Segment Cover
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given closed intervals on the number line.
For every query , choose as few intervals as possible from the given collection so that their union covers the entire interval . Selected intervals may overlap, but no uncovered gap is permitted.
If coverage is impossible, print -1.
Input
- The first line contains .
- The next lines contain intervals .
- The final lines contain query endpoints .
Output
Print the minimum number of intervals per query, or -1 if impossible.
Subtasks
- Subtask 1 (20 points): ; ; ; ; ; .
- Subtask 2 (30 points): ; ; ; ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Input
2 3
1 3
2 4
1 3
1 4
3 4
Output
1
2
1
Explanation
Interval requires one given interval. Covering requires both and . Interval is covered by the second interval.