Beats 100%
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[] nums, int[][] queries) {\n        Arrays.sort(queries, (x, y) -> {\n            return x[0] == y[0] ? x[1] - y[1] : x[0] - y[0];\n        });\n        PriorityQueue<int[]> pq = new PriorityQueue<int[]>((x, y) -> {\n            return y[1] - x[1];\n        });\n\n        int arr[] = new int[nums.length + 2];\n        int n = nums.length;\n        int pos = 0;\n        int anss = 0;\n        for (int i = 0; i < n; i++) {\n            while (pos < queries.length && queries[pos][0] <= i)\n                pq.add(queries[pos++]);\n            if (i > 0)\n                arr[i] += arr[i - 1];\n            nums[i] = nums[i] - arr[i];\n            while (nums[i] > 0) {\n                if (pq.isEmpty())\n                    return -1;\n                int t[] = pq.poll();\n                if (t[1] >= i) {\n                    arr[i + 1]++;\n                    arr[t[1] + 1]--;\n                    nums[i]--;\n                } else\n                    anss++;\n            }\n        }\n        return anss + pq.size();\n    }\n}\n```
['Java']