Python3 || sort, heap  || T/S: 99% / 92%
Here\'s the plan:\n1. We sort queries by their first elements, and we initialize arr to keep track of decrements applied to nums as we apply each query used.\n\
Here\'s the plan:\n1. We sort `queries` by their first elements, and we initialize `arr` to keep track of decrements applied to nums as we apply each query used.\n\n1. We iterate over `nums` and apply the queries for each element from the heap. We track the aggregrate decrements in `arr`. For each query applied,we decrement `ans`.\n2. If we exhaust all queries applying to an element of `nums` and that element is not zero, then no answer is possible, and we return -1.\n3. If we complete the iteration successfully, we return `ans`.\n\n\n```python3 []\nclass Solution:\n    def maxRemoval(self, nums, queries):\n \n        n, decr, idx = len(nums), 0, 0\n        q = ans = len(queries)\n\n        arr, heap = [0] * (n + 1), []\n        queries.sort(key=lambda x: x[0])\n\n        for i, num in enumerate(nums):\n            decr-= arr[i]\n            num-= decr\n\n            while q > idx and queries[idx][0] == i:\n                heappush(heap, (-queries[idx][1]))  \n                idx+= 1\n\n            while num > 0 and heap and -heap[0] >= i:\n                arr[1 - heappop(heap)]+= 1\n                ans-= 1\n                decr+= 1\n                num-= 1\n\n            if num > 0: return -1\n \n        return ans\n```\n[https://leetcode.com/problems/zero-array-transformation-iii/submissions/1462747331/](https://leetcode.com/problems/zero-array-transformation-iii/submissions/1462747331/)\n\nI could be wrong, but I think that time complexity is *O*(*N* + *Q* log *Q) and space complexity is *O*(*N* + *Q*), in which *N* ~ `len(nums)` and *Q* ~ `len(queries)`.
['Python3']