SnowflakeOA #38
Minimum Segments
估计中等可在线判题
You are given closed intervals and may add exactly one extra closed interval with length b−a≤k. Find the minimum number of connected blocks after merging. Touching at the same endpoint counts as connected; intervals that differ by 1 are not automatically connected.
输入格式
The first line contains n k, followed by n lines of a b. 1≤n≤200000, 1≤a≤b≤10⁹, 1≤k≤10⁹. The added interval may have length 0.
输出格式
Output the single integer required by the problem.
样例 1
输入:
4 2
1 2
2 4
5 8
10 11
输出:
2
样例 2
输入:
2 1
1 1
2 2
输出:
1
样例 3
输入:
1 1
1 100
输出:
1
样例说明
The answers to the three public examples are, in order: 2; 1; 1. The examples were rechecked by independent enumeration, state search, or direct simulation.