#P10793. 『SpOI - R1』Double Champions

    ID: 10999 远端评测题 1250ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划 DP贪心单调队列O2优化排序

『SpOI - R1』Double Champions

Problem Description

This problem contains multiple test cases.

Now there are several cells arranged in a line.

You are given nn intervals. Each interval ii can cover every cell in the range [li,ri][l_i,r_i] (for example, the interval [1,2][1,2] can cover cells 1,21,2).

Now you need to group these intervals. The contribution of each group is the total length of the intersection of all intervals in that group.

You need to find the minimum number of groups to split these intervals into, such that the contribution of every group is w\geq w. If there is no solution, output No.

Input Format

The first line contains an integer TT, the number of test cases.

For each test case, the first line contains two integers n,wn,w.

The next nn lines each contain two integers li,ril_i,r_i, describing an interval.

Output Format

For each test case, output one line with the answer: the minimum number of groups, or the string No if there is no solution.

2
5 3 
6 10
6 8 
3 5 
7 9 
1 9
5 5
5 10
3 8
6 10
4 10
5 9
3
3

Hint

Explanation for Sample #1

Number the intervals in the input order as ,,,,①,②,③,④,⑤.

The 55 intervals can be divided into the following 33 groups: {,},{},{③⑤}\{①,④\},\{②\},\{③⑤\}. Then the contribution of each group (i.e., the intersection size) is 3,3,33,3,3 respectively, which satisfies the requirement that each group’s contribution is 3\geq 3. It can be proven that among all valid partitions, 33 groups is the minimum.

Constraints

Please pay attention to the impact of constant factors on program efficiency.

This problem uses bundled testdata and subtask dependencies.

For 100%100\% of the testdata, 1T201\leq T\leq 20, 1n2×1051\leq n\leq 2\times 10^5, 0w1060\leq w\leq 10^6, 1liri1061\leq l_i\leq r_i\leq 10^6.

Subtask nn\leq w,li,riw,l_i,r_i\leq Score Subtask Dependencies
1 88 1515 1010 None
2 1111 2020 1
3 1.5×1031.5\times 10^3 10410^4 2525 1,2
4 2×1052\times 10^5 10610^6 5555 1,2,3

Translated by ChatGPT 5