Exam Study Planning
InterviewTime limit1sMemory limit1024 MB
Given exams with start, early-exit, and full end times plus study needs, find the most exams you can pass by studying in free time before each exam starts.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
You have a lot of exams today, and you have not prepared for any of them yet. From experience, you know that if you study enough for an exam, you will pass it quickly, well within the time limit. You also know exactly how much study time each exam needs to pass within its time limit. If you study less than that, you will fail.
Your university requires you to attend all of your exams. You may leave an exam early only if you know for sure that you passed it.
You may start studying at time , but you can only study while you are not taking an exam. Studying for an exam does not have to happen in one contiguous block. You may stop and resume it.
Given the full exam schedule, including when each exam starts, how long it takes, how long you need to study for it, and how quickly you can finish an exam you studied for, how many exams can you pass at most?
Input
The input consists of:
-
One line with an integer (), the number of exams you have to attend.
-
lines, the th of which contains four integers describing an exam:
- (), the start time of the th exam,
- (), the end time of the th exam if you prepare for it,
- (), the end time of the th exam if you do not prepare for it,
- (), the time needed to prepare the th exam.
The exams are given in ascending order of start time and do not overlap, i.e. holds for .
Output
Output the maximum number of exams you can pass.