PriorityQueue
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```csharp []
public class Solution {
    public int MaxRemoval(int[] nums, int[][] queries) {
            queries = queries.OrderBy(q => q[0]).ThenByDescending(q => q[1]).ToArray();

			int len = nums.Length, res = 0, qLen = queries.Length;
			PriorityQueue<int, int> pq = new();

			int[] end = new int[len+1];
			int cur = 0, idx = 0;

			for (int i = 0; i < len; i++) // Iterate each item
			{
				cur += end[i]; // update query freq with ended here
				while (idx < qLen && queries[idx][0] <= i) // Enqueue the queries which started before cur index
				{
					pq.Enqueue(-queries[idx][1], -queries[idx++][1]);
				}

				while (cur < nums[i])
				{
					if (pq.Count == 0 || (-pq.Peek()) < i)
						return -1;

					end[-pq.Dequeue() + 1]--;
					cur++;
				}
			}
			

			return pq.Count;
  
    }
}
```
['C#']