Schedule as many exams as possible before their deadlines, choosing an order that maximizes the count.
You are given a set of exams. Each exam takes one day to complete and has a deadline by which it must be finished. Starting from day 1, you may take at most one exam per day.
Your task is to choose a subset of exams and an order to take them so that every chosen exam is completed no later than its deadline, while the total number of completed exams is as large as possible.
Return the maximum number of exams that can be passed.
Note: This is a prep-oriented rephrasing of the classic scheduling problem; interpret the pair as a deadline-based exam scheduling constraint.
Print one integer — the maximum number of exams that can be completed on time.
Example 1
Input
3 3 5 1 2 2 4
Output
2
Explanation
One optimal plan is to complete the exam with deadline 2 on day 1 and the exam with deadline 4 on day 2. The exam with deadline 5 can still be skipped, so the maximum count is 2.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.