Heap
\n# Code\npython3 []\nfrom heapq import heappush, heappop\n\nclass Solution:\n    def maxRemoval(self, nums, queries):\n        queries.sort()\n        candidat
\n# Code\n```python3 []\nfrom heapq import heappush, heappop\n\nclass Solution:\n    def maxRemoval(self, nums, queries):\n        queries.sort()\n        candidate = [] \n        chosen = [] \n        ans = 0\n        n = len(nums)\n        j = 0\n        \n        for i in range(n):\n            while j < len(queries) and queries[j][0] == i:\n                heappush(candidate, -queries[j][1])  \n                j += 1\n            \n            nums[i] -= len(chosen)\n            \n            while nums[i] > 0 and candidate and -candidate[0] >= i:\n                ans += 1\n                heappush(chosen, -heappop(candidate)) \n                nums[i] -= 1\n            \n            if nums[i] > 0:\n                return -1\n            \n            while chosen and chosen[0] == i:\n                heappop(chosen)\n        \n        return len(queries) - ans\n\n```
['Python3']