#P1668. [USACO04DEC] Cleaning Shifts S

    ID: 2459 远端评测题 1000ms 512MiB 尝试: 11 已通过: 4 显示难度普及+/提高− 上传者: 标签>动态规划 DP图论贪心2004线段树USACO最短路

[USACO04DEC] Cleaning Shifts S

Problem Description

There are T(1≤T≤106)T(1\le T\le 10^6) time slots in a day. John plans to schedule his N(1≤N≤2.5×104)N(1\le N\le 2.5\times 10^4) cows to be on duty to clean the barn. Each cow has her own available interval [Si,Ei](1≤Si≤Ei≤T) [S_i,E_i](1\le S_i\le E_i\le T) and only cows who are free can be scheduled. Moreover, every time slot must have a cow on duty.

What is the minimum number of cows required to cover all time slots? If it is impossible to make a valid schedule, output −1-1.

Input Format

The first line: NN, TT.

Lines 22 to N+1N+1: SiS_i, EiE_i.

Output Format

One line, output the minimum number of cows.

3 10
1 7
3 6
6 10
2

Hint

1≤T≤1061\le T\le 10^6,N≤2.5×104N\le 2.5\times 10^4,1≤Si≤Ei≤T1\le S_i\le E_i\le T。

Update On 2023/08/08\text{Update On 2023/08/08}:Added a set of hack testdata, see details here. Ruled out wrong solutions with time complexity O(nt)\mathcal O(nt).

Translated by ChatGPT 5