Problem library

Quest Deadlines

Hard
greedyheap

Each entry of quests is [duration, deadline]. You play one quest at a time starting at time 0, and a quest counts only if it finishes at or before its deadline. You may skip quests and play the rest in any order.

Return the largest number of quests you can complete. The largest test has 20,000 quests.

Examples

Input: quests = [[100,200],[200,1300],[1000,1250],[2000,3200]]
Output: 3
Input: quests = [[5,3]]
Output: 0