Perfect solution {:)}
\n\n# Code\njava []\nclass Solution {\n    public int maxRemoval(int[] nums, int[][] queries) {\n        Arrays.sort(queries, (q1,q2) -> q1[0]-q2[0]);\n\n      
\n\n# Code\n```java []\nclass Solution {\n    public int maxRemoval(int[] nums, int[][] queries) {\n        Arrays.sort(queries, (q1,q2) -> q1[0]-q2[0]);\n\n        PriorityQueue<int[]> pq = new PriorityQueue<>((q1,q2) -> q2[1]-q1[1]);\n\n        int q = 0, d = 0, res = 0;\n        int[] delta = new int[nums.length+1];\n        for(int i=0; i<nums.length; i++){\n            d+=delta[i];\n            if((nums[i]-d)>0){\n                while(q < queries.length && queries[q][0]<=i){\n                    pq.offer(queries[q++]);\n                }\n            }\n            while((nums[i]-d)>0 && !pq.isEmpty() && pq.peek()[1]>=i){\n                int[] query = pq.poll();\n                res++;\n                delta[query[0]]++;\n                delta[query[1]+1]--;\n                d++;\n            }\n            if(nums[i]-d>0){\n                return -1;\n            }\n        }\n\n        return queries.length - res;\n\n    }\n}\n```
['Java']