# [Solution] Scheduling a Meeting Round F 2022 - Kick Start 2022 Solution

### Problem

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 of Tech Leads.

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

### Input

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

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

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

lines follow. The -th of these contains three integer numbers , , and . These numbers represent that a Tech Lead has a scheduled meeting between the hours and , not including the endpoints (that is, the meeting can be seen as an interval).

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

### Output

For each test case, output one line containing `Case #: `

, where is the test case number (starting from 1) and is the minimum number of scheduled meetings that needs to be canceled so that Ada can schedule an -hour-long meeting with at least Tech Leads.

### Note on the Time Format

The timeline of this problem can be seen as an interval — that is, consecutive hours, where can be bigger than .

A meeting in the interval means the meeting starts at the beginning of the -th hour, and ends at the beginning of the -th hour, covering the whole time period in between, without any gaps (i.e. the interval is continuous). Endpoints are not included in an 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.

### Limits

Time limit: 40 seconds.

Memory limit: 1 GB.

.

, for all .

, for all .

#### Test Set 1

.

.

.

#### Test Set 2

.

.

.

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

In Sample Case #2, Ada needs to schedule a two-hour-long meeting with all three Tech Leads. She can schedule such a meeting in the interval , which will require meetings and to be canceled. Another option is to schedule a meeting in the interval . Both options require two meetings to be canceled, which is the minimum number possible.

In Sample Case #3, Ada needs to schedule a three-hour-long meeting with at least two Tech Leads. She can schedule this meeting in the interval , and meet with Tech Leads and . This will require meeting to be canceled, and this is the optimal solution here.

## No comments:

## Post a Comment