Python | one Heap | O((n+q)log(n+q))
Code\npython3 []\nclass Solution:\n    def maxRemoval(self, nums: List[int], queries: List[List[int]]) -> int:\n        queries.sort(key = lambda e: (e[0],-e[1]
# Code\n```python3 []\nclass Solution:\n    def maxRemoval(self, nums: List[int], queries: List[List[int]]) -> int:\n        queries.sort(key = lambda e: (e[0],-e[1]))\n        events = []\n        for i,num in enumerate(nums):\n            events.append((i,1,num))\n        for j,(l,r) in enumerate(queries):\n            events.append((l,0,j))\n            events.append((r,2,j))\n        events.sort()\n        h = []\n        passed = [False]*len(queries)\n        covered = set()\n        overlapped = 0\n        res = 0\n        for e,t,j in events:\n            if t == 0:\n                heappush(h, (-queries[j][1],j))\n                overlapped += 1\n            elif t == 2:\n                overlapped -= 1\n                if j in covered:\n                    covered.remove(j)\n                    res += 1\n                passed[j] = True\n            else:\n                if j > overlapped:\n                    return -1\n                while len(covered) < j:\n                    while passed[h[0][1]]:\n                        heappop(h)\n                    _,k = heappop(h)\n                    covered.add(k)\n        return len(queries) - (res + len(covered))\n\n                    \n```
['Python3']