sort + heap + sweepline
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python3 []\nfrom sortedcontainers import SortedList\n\nclass Solution:\n    def maxRemoval(self, nums: List[int], queries: List[List[int]]) -> int:\n        n = len(nums)\n        queries.sort(key=lambda q: q[0])\n\n        d = [0] * (n + 1)\n        hp = []\n        cnt = 0\n        j = 0\n        for i in range(n):\n            while j < len(queries) and queries[j][0] <= i:\n                heappush(hp, -queries[j][1])\n                j += 1\n            k = 0\n            cnt += d[i]\n            while cnt < nums[i]:\n                if len(hp) == 0:\n                    break\n                e = -heappop(hp)\n                if e < i:\n                    break\n                cnt += 1\n                d[e+1] += -1\n            if cnt < nums[i]:\n                return -1\n        return len(hp)\n```
['Python3']