#P1668. [USACO04DEC] Cleaning Shifts S

    ID: 8319 远端评测题 1000ms 512MiB 尝试: 4 已通过: 1 难度: 6 上传者: 标签>动态规划,dp图论贪心2004线段树USACO最短路

[USACO04DEC] Cleaning Shifts S

Description

There are T(1T106)T(1\le T\le 10^6) time slots in a day. John plans to schedule his N(1N2.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](1SiEiT) [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

1T1061\le T\le 10^6N2.5×104N\le 2.5\times 10^41SiEiT1\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