#P16850. [GKS 2021 #D] Cutting Intervals

[GKS 2021 #D] Cutting Intervals

Problem Description

You are given NN intervals. An interval can be represented by 22 positive integers LiL_i and RiR_i - the interval starts at LiL_i and ends at RiR_i, represented as [Li,Ri][L_i, R_i]. Intervals may not be unique, so there might be multiple intervals with both equal LiL_i and equal RiR_i.

You are allowed to perform a maximum of CC cuts. A cut at XX will cut all intervals [L,R][L, R] for which L<XL < X and X<RX < R. Cutting an interval at XX is defined as splitting the interval into 22 intervals - [L,X][L, X] and [X,R][X, R]. Note that cuts can only be performed at integer points. Also, cutting at an endpoint of an interval (X=LX = L or X=RX = R) has no effect and does not split the interval.

You need to find the maximum number of intervals that can be obtained through a maximum of CC cuts.

Input Format

The first line of the input contains the number of test cases, TT. TT test cases follow.

Each test case starts with a line containing 22 integers, NN and CC, denoting the number of intervals and the maximum number of cuts you can perform respectively. NN lines follow.

The ii-th line contains 22 integers, LiL_i and RiR_i, describing the ii-th interval.

Output Format

For each test case, output one line containing Case #x\#x: yy, where xx is the test case number (starting from 11) and yy is the maximum number of intervals that can be obtained through at most CC cuts, as described above.

1
3 3
1 3
2 4
1 4
Case #1: 7

Hint

In the provided sample, cuts should be performed at 22 and 33 to get the maximum number of intervals.

After the first cut at 22, the intervals would be {[1,2],[2,3],[2,4],[1,2],[2,4]}\{[1, 2], [2, 3], [2, 4], [1, 2], [2, 4]\}.

After the second cut at 33, the intervals would be $\{[1, 2], [2, 3], [2, 3], [3, 4], [1, 2], [2, 3], [3, 4]\}$.

It can be seen that no interval can be cut further, so the answer is 77.

Limits

Memory limit: 11 GB.

1T1001 \le T \le 100.

Test Set 11

1N5001 \le N \le 500.

1C1051 \le C \le 10^5.

1Li<Ri1041 \le L_i < R_i \le 10^4 for all ii.

Test Set 22

1N1051 \le N \le 10^5.

1C10181 \le C \le 10^{18}.

1Li<Ri10131 \le L_i < R_i \le 10^{13} for all ii.