PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000189. Số thứ K trong hợp các đoạn (K-th Number in the Union of Segments)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Số thứ K trong hợp các đoạn (K-th Number in the Union of Segments)
K-th Number in the Union of Segments
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
You are given closed integer segments . Segment contains every integer with , including both endpoints.
Write every integer from every segment into one list and sort the list in nondecreasing order. An integer belonging to multiple segments appears once for each such segment. The list has elements.
Find the element at zero-based index in the sorted list. In particular, refers to its smallest element.
Input
- The first line contains integers and .
- Each of the next lines contains , , describing segment .
Output
- Print one integer: the value at zero-based position .
Subtasks
- Subtask 1 (20 points): ; for every ; .
- Subtask 2 (30 points): ; for every ; .
- Subtask 3 (50 points): ; for every ; .
Examples
Input
3 4
-1 1
0 2
2 2
Output
1
Explanation
The segments are , , and . They contribute . Sorting gives . At zero-based index (the fifth position), the value is .