There are `n` different online courses numbered from `1` to `n`. You are given an array `courses` where `courses[i] = [duration_i, lastDay_i]` indicate that the `i`th course should be taken **continuously** for `duration_i` days and must be finished before or on `lastDay_i`. You will start on the `1st` day and you cannot take two or more courses simultaneously. Return the **maximum number of courses** that you can take.
Example 1
Input: courses = [[100,200],[200,1300],[1000,1250],[2000,3200]]
Output: 3
Explanation: Take the courses in order of deadline: the 100-day course ends on day 100 (deadline 200), the 1000-day course ends on day 1100 (deadline 1250), and the 200-day course ends on day 1300 (deadline 1300). Adding the 2000-day course would end on day 3300, past its deadline of 3200, so the maximum is 3.
Example 2
Input: courses = [[1,2]]
Output: 1
Explanation: The single course fits (1 day, deadline 2).
Example 3
Input: courses = [[3,2],[4,3]]
Output: 0
Explanation: Neither course can finish by its deadline.
Process courses in deadline order and greedily take each one. If the running total time exceeds the current deadline, drop the single longest course taken so far (from a max-heap of durations) — swapping it out never reduces the count and can only free up time.
Run checks all cases above. Submit evaluates all test cases.