PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BF0000032. Chọn số nguyên theo các đoạn (Intervals)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chọn số nguyên theo các đoạn (Intervals)
Intervals
Source: SPOJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given closed integer intervals , choose a set of distinct integers containing at least chosen integers in each interval. Minimize .
Only distinct integers are selected; selecting the same integer twice does not help.
This Extended version omits the original count of independent test cases.
Input
First line . Then lines .
Output
Print the minimum number of selected integers.
Subtasks
- Subtask 1 (20 points): $1\le n\le20; 0\le a_i\le b_i\le30; 1\le c_i\le b_i-a_i+1$.
- Subtask 2 (30 points): $1\le n\le2500; 0\le a_i\le b_i\le3000; 1\le c_i\le b_i-a_i+1$.
- Subtask 3 (50 points): $1\le n\le50000; 0\le a_i\le b_i\le50000; 1\le c_i\le b_i-a_i+1$.
Examples
Input
3
1 3 2
2 5 2
4 5 1
Output
3
Explanation
The selected integers cover the three intervals with respectively , , and points. At least three points are needed, as the first and last intervals need disjoint selected points except where they do not overlap.