JAVA 78ms(beats 100%) with PQ and sort, greedy
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```java []\nclass Solution {\n    public int maxRemoval(int[] n, int[][] q) {\n        Arrays.sort(q, (o1,o2)->(o1[0]-o2[0]));\n        int qi=0, c=0, a=0;\n        int[] d = new int[n.length+1];\n\n        PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());\n\n        for(int ni=0;ni<n.length; ni++){\n            c+=d[ni];\n            if(c<n[ni]){\n                for(; qi<q.length&&q[qi][0]<=ni; qi++){\n                    if(q[qi][1]<ni);\n                    else pq.add(q[qi][1]);\n                }\n                while(c<n[ni]){\n                    if(pq.isEmpty() || pq.peek()<ni)return -1;\n                    c++; d[pq.poll()+1]--; a++;\n                }\n            }\n        }\n        return q.length-a;\n    }\n}\n```
['Java']