#P16892. [GKS 2022 #F] Scheduling a Meeting

    ID: 19220 远端评测题 5000ms 1024MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>树状数组2022扫描线Google Kick Start

[GKS 2022 #F] Scheduling a Meeting

Problem Description

Scheduling meetings at Google is not an easy task. Even with the help of Google Calendar, Ada has a lot of difficulty with it!

Ada works as a Software Engineer at Google, and needs to get approval for her new project. In order to get an approval, she needs to meet with at least KK of NN Tech Leads.

Ada has access to the calendars of all NN Tech Leads. For each Tech Lead, Ada can see all their scheduled meetings. The timeline in this problem can be viewed as DD consecutive hours, and all meetings are in [0,D][0, D] hours range, with both ends being integer numbers. Scheduled meetings, even for the same person, can overlap (people are notorious for this at Google!).

Ada needs to schedule an XX-hour-long meeting in the interval of [0,D][0, D] hours, with both ends being integer numbers as well. At least KK of NN Tech Leads should be present for the whole meeting, that is their calendar should be completely free for the entire meeting duration.

Unfortunately, it might be the case that it is already impossible to find a slot to schedule such an XX-hour-long meeting. In that case, Ada will need to persuade some Tech Leads to cancel their existing meetings.

What is the minimum number of scheduled meetings that need to be canceled so that Ada can meet with at least KK Tech Leads?

Input Format

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

The first line of each test case contains 44 integers NN, KK, XX, and DD. NN represents the number of Tech Leads, KK is the minimum number of Tech Leads Ada needs to meet, XX is the length of the meeting that needs to be set up, and DD is the upper bound of the [0,D][0, D] hour range representing the timeline of the problem — no meeting can end after DD.

The second line of each test case contains an integer MM, representing the number of scheduled meetings.

MM lines follow. The ii-th of these contains 33 integer numbers PiP_i, LiL_i, and RiR_i. These numbers represent that a Tech Lead PiP_i has a scheduled meeting between the hours LiL_i and RiR_i, not including the endpoints (that is, the meeting can be seen as an (Li,Ri)(L_i, R_i) interval).

Note that all MM meetings in the test case are independent, even if some of them have the same starting and ending time.

Output Format

For each test case, output 11 line containing Case #xx: yy, where xx is the test case number (starting from 11) and yy is the minimum number of scheduled meetings that needs to be canceled so that Ada can schedule an XX-hour-long meeting with at least KK Tech Leads.

Note on the Time Format

The timeline of this problem can be seen as an [0,D][0, D] interval — that is, DD consecutive hours, where DD can be bigger than 2424.

A meeting in the interval (L,R)(L, R) means the meeting starts at the beginning of the LL-th hour, and ends at the beginning of the RR-th hour, covering the whole time period in between, without any gaps (i.e. the interval is continuous). Endpoints are not included in an (L,R)(L, R) interval. For Tech Leads attending Ada's scheduled meeting, Ada's new meeting can border some of their other non-canceled meetings — that is, it can start right when another meeting ends, or end right when another meeting starts, or both. A Tech Lead cannot attend Ada's meeting if they have any other non-canceled meetings overlapping with Ada's meeting at any point.

See explanation of the sample test cases for more clarity.

3
3 2 2 6
5
1 3 5
2 1 3
2 2 6
3 0 1
3 3 6
3 3 2 6
5
1 3 5
2 1 3
2 2 6
3 0 1
3 3 6
3 2 3 6
5
1 3 5
2 1 3
2 2 6
3 0 1
3 3 6
Case #1: 0
Case #2: 2
Case #3: 1

Hint

In Sample Case #1\#1, Ada needs to schedule a 22-hour-long meeting with at least 22 Tech Leads. She can schedule such a meeting between hours 11 and 33 with Tech Leads #1\#1 and #3\#3. In this case, no existing meetings need to be canceled.

In Sample Case #2\#2, Ada needs to schedule a 22-hour-long meeting with all 33 Tech Leads. She can schedule such a meeting in the interval [0,2][0, 2], which will require meetings 22 and 44 to be canceled. Another option is to schedule a meeting in the interval [1,3][1, 3]. Both options require 22 meetings to be canceled, which is the minimum number possible.

In Sample Case #3\#3, Ada needs to schedule a 33-hour-long meeting with at least 22 Tech Leads. She can schedule this meeting in the interval [0,3][0, 3], and meet with Tech Leads #1\#1 and #3\#3. This will require meeting 44 to be canceled, and this is the optimal solution here.

Limits

1T1001 \le T \le 100.

1PiN1 \le P_i \le N, for all ii.

0Li<RiD0 \le L_i < R_i \le D, for all ii.

Test Set 11

1XD81 \le X \le D \le 8.

1KN101 \le K \le N \le 10.

0M200 \le M \le 20.

Test Set 22

1XD1051 \le X \le D \le 10^5.

1KN1051 \le K \le N \le 10^5.

0M1050 \le M \le 10^5.