Simple solution using 2 priorityQueue
\n# Code\njava []\nclass Solution {\n    public int maxRemoval(int[] nums, int[][] queries) {\n        int s=0;\n        int qp=0;\n       PriorityQueue<Integer
\n# Code\n```java []\nclass Solution {\n    public int maxRemoval(int[] nums, int[][] queries) {\n        int s=0;\n        int qp=0;\n       PriorityQueue<Integer>pq=new PriorityQueue<>((a,b)->b-a);\n       PriorityQueue<Integer>pq1=new PriorityQueue<>((a,b)->a-b);\n       Arrays.sort(queries,(a,b)->a[0]-b[0]);\n       for(int i=0;i<nums.length;i++){\n        int x=nums[i];\n       \n        while(qp<queries.length&&queries[qp][0]==i){\n         \n            pq.offer(queries[qp][1]);\n            qp++;\n         \n        }\n         x-=pq1.size();\n        while(x>0&&pq.size()>0&&pq.peek()>=i){\n            s++;\n            x--;\n            pq1.offer(pq.poll());\n\n        }\n\n       \n        if(x>0)return -1;\n        while(pq1.size()>0&&pq1.peek()<=i)pq1.poll();\n\n       }\n       return queries.length-s;\n\n    }\n}\n```
['Java']