Scheduling a Meeting

아직 제출이 없습니다시간 제한40초메모리 제한1024 MB

문제

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 K\mathbf{K} of N\mathbf{N} Tech Leads.

Ada has access to the calendars of all N\mathbf{N} Tech Leads. For each Tech Lead, Ada can see all their scheduled meetings. The timeline in this problem can be viewed as D\mathbf{D} consecutive hours, and all meetings are in \[0,D]\[0, \mathbf{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 X\mathbf{X}-hour-long meeting in the interval of \[0,D]\[0, \mathbf{D}] hours, with both ends being integer numbers as well. At least K\mathbf{K} of N\mathbf{N} 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 X\mathbf{X}-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 K\mathbf{K} Tech Leads?

입력

The first line of the input gives the number of test cases, T\mathbf{T}. T\mathbf{T} test cases follow.

The first line of each test case contains four integers N\mathbf{N}, K\mathbf{K}, X\mathbf{X}, D\mathbf{D}. N\mathbf{N} represents the number of Tech Leads, K\mathbf{K} is the minimum number of Tech Leads Ada needs to meet, X\mathbf{X} is the length of the meeting that needs to be set up, and D\mathbf{D} is the upper bound of the \[0,D]\[0, \mathbf{D}] hour range representing the timeline of the problem — no meeting can end after D\mathbf{D}.

The second line of each test case contains an integer M\mathbf{M}, representing the number of scheduled meetings.

M\mathbf{M} lines follow. The ii-th of these contains three integer numbers P_i\mathbf{P\_i}, L_i\mathbf{L\_i}, and R_i\mathbf{R\_i}. These numbers represent that a Tech Lead P_i\mathbf{P\_i} has a scheduled meeting between the hours L_i\mathbf{L\_i} and R_i\mathbf{R\_i}, not including the endpoints (that is, the meeting can be seen as an (L_i,R_i)(\mathbf{L\_i}, \mathbf{R\_i}) interval).

Note that all M\mathbf{M} meetings in the test case are independent, even if some of them have the same starting and ending time.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum number of scheduled meetings that needs to be canceled so that Ada can schedule an X\mathbf{X}-hour-long meeting with at least K\mathbf{K} Tech Leads.

힌트

The timeline of this problem can be seen as an \[0,D]\[0, \mathbf{D}] interval — that is, D\mathbf{D} consecutive hours, where D\mathbf{D} 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.