Scheduling a Meeting
Time limit40sMemory limit1024 MB
Find the fewest scheduled meetings to cancel so that K of N Tech Leads are free for one X-hour slot within [0, D].
- Level
Medium6 of 10
- Topics
- Intervals, Sorting, Implementation
- Solved
- No attempts yet
Problem
Scheduling meetings at Google is not an easy task. Even with Google Calendar, Ada has a hard time with it.
Ada is a Software Engineer at Google. To get approval for her new project, she must meet with at least of the Tech Leads.
Ada can see the calendars of all Tech Leads, including every scheduled meeting. The timeline is consecutive hours, and all meetings lie in the range with integer endpoints. Scheduled meetings can overlap, even for the same person.
Ada needs to schedule a meeting of hours within , with integer start and end times. At least Tech Leads must be present for the whole meeting, which means their calendars must be completely free for its entire duration.
Sometimes no such slot exists. In that case, Ada must persuade some Tech Leads to cancel their existing meetings.
Find the minimum number of scheduled meetings that must be canceled so that Ada can meet with at least Tech Leads.
Input
The first line contains the number of test cases . Then test cases follow.
The first line of each test case contains four integers , , , and . is the number of Tech Leads, is the minimum number of Tech Leads Ada needs to meet, is the length of the meeting to schedule, and is the upper bound of the range . No meeting can end after .
The second line contains an integer , the number of scheduled meetings.
Each of the next lines contains three integers , , and . This means Tech Lead has a scheduled meeting in the open interval , so the endpoints are not included. All meetings are independent, even if some share the same start and end times.
Output
For each test case, output one line in the form Case #x: y. Here is the test case number starting from 1, and is the minimum number of scheduled meetings that must be canceled so that Ada can schedule an -hour meeting with at least Tech Leads.
Hint
The timeline can be seen as the interval , that is, consecutive hours. can be larger than 24.
A meeting starts at the beginning of hour and ends at the beginning of hour , covering the whole time between them without gaps. The endpoints are not included. Ada's new meeting may border other non-canceled meetings of a Tech Lead: it can start right when another meeting ends, end right when another meeting starts, or both. A Tech Lead cannot attend Ada's meeting if any other non-canceled meeting overlaps with it at any point.