Blockade Duty Schedule
Time limit1sMemory limit512 MB
Find the largest M such that a daily duty schedule exists where at least M students are on duty at every moment, respecting each student's free periods and daily minute limit.
- Level
Medium7 of 10
- Topics
- Intervals, Binary search, Greedy
- Solved
- No attempts yet
Problem
Students at a faculty fell out with the dean and decided to blockade the faculty building. Keeping the blockade means a fixed number of students must be physically present in the building for all 24 hours of the day. The organizers want to split the duty shifts as fairly as they can, so they agreed on these rules.
- The duty schedule is the same every day.
- A student can be on duty only while free of other obligations.
- Each student sets a limit on the total time spent on duty in one day, from midnight to midnight.
- To keep things simple, a duty starts and ends only on a full hour or a half hour. For example 16:00 or 16:30 is allowed, 16:15 is not.
- A student must be free for the whole duty. For example, if a student is free only from 16:05, the schedule cannot put her on duty starting at 16:00.
- The smallest number of students on duty over any part of the day is made as large as possible. That improves the chances the blockade holds.
Write a program that finds the largest for which a schedule satisfying all of the rules above exists and at least students are on duty at every moment of the day, from midnight to midnight.
Assume a change of duty is instantaneous. If two students leave the blockade and two others take their place, treat the blockade as having two students present for the whole changeover.
Input
The first line has an integer (), the number of students who want to join the blockade. Then come blocks, one per student.
Each block starts with two integers () and (). is the number of time periods in which student is free of other obligations and can join the blockade, and is the largest total number of minutes that student will spend on duty in one day.
The remaining lines of the block each hold the start time and the end time of one continuous period in which the student is free, separated by a space. Periods may overlap, and their union is the time the student can be present at the blockade.
Times use the format HH:MM (, ). Midnight is written 00:00. When the end time comes before the start time, the student can stay at the blockade past midnight. For example, the period 23:00 03:00 means the student can be present from 23:00 until 03:00 the next morning. When the start time and the end time are equal, the student can be at the blockade for all 24 hours.
Output
Print one integer, the largest number of students that can be at the blockade at every moment of the day under the assumptions above.