cswork / OA打开练习工作台

SnowflakeOA #18

Smallest Set Covering Intervals

估计困难可在线判题

考点(AI 标注)贪心调度前缀和区间

Given closed integer intervals, find the smallest set of integers such that every interval contains at least two distinct integers from the set. The original text allows single-point intervals but does not define the output when there is no solution; this site's protocol specifies outputting −1 in that case, without removing any originally valid input range.

输入格式

The first line contains n, followed by n lines of first last. 1≤n≤100000, 0≤first≤last≤10⁹.

输出格式

Output the single integer required by the problem.

样例 1

输入:

3
0 2
1 3
2 3

输出:

3

样例 2

输入:

1
0 0

输出:

-1

样例 3

输入:

3
1 3
1 4
2 5

输出:

2

样例说明

The answers to the three public examples are, in order: 3; -1; 2. All examples have been verified by independent small-scale enumeration or state search.