Greedy Approach on it's ^PEAK^ | Double Priority Queue + Sorting Explained Solution
\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& q) {\n        // Priority queue to store potential removable indices in 
```\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& q) {\n        // Priority queue to store potential removable indices in decreasing order\n        priority_queue<int> candidate;\n\n        // Priority queue to store the currently "chosen" indices in increasing order\n        // This helps efficiently check and remove indices that are no longer valid\n        priority_queue<int, vector<int>, greater<>> choosen;\n\n        int n = nums.size(); // Number of elements in the nums array\n\n        // Sort the queries `q` based on the starting index (q[i][0]) in ascending order\n        sort(q.begin(), q.end(), [](vector<int> &a, vector<int> &b) {\n            return a[0] < b[0];\n        });\n\n        int j = 0; // Pointer for iterating through the queries\n        int ans = 0; // Count of successful removals\n\n        for (int i = 0; i < n; i++) {\n            // Remove indices from `choosen` that are no longer valid (expired)\n            while (choosen.size() && choosen.top() < i) {\n                choosen.pop();\n            }\n\n            // Adjust the allowable removals for `nums[i]` based on the size of `choosen`\n            nums[i] -= choosen.size();\n\n            // Add all queries that start at index `i` to the candidate queue\n            while (j < q.size() && q[j][0] == i) {\n                candidate.push(q[j++][1]); // Push the ending index (q[j][1]) into the candidate queue\n            }\n\n            // Process candidates to fulfill `nums[i]` removals\n            while (nums[i] > 0 && candidate.size() && candidate.top() >= i) {\n                nums[i]--; // Decrease the number of removals needed for `nums[i]`\n                choosen.push(candidate.top()); // Add the index to `choosen` as it\'s now in use\n                ans++; // Increment the count of successful removals\n                candidate.pop(); // Remove the used candidate from the queue\n            }\n\n            // If there are still removals needed for `nums[i]` but no valid candidates, return -1\n            if (nums[i] > 0) return -1;\n        }\n\n        // Return the number of unfulfilled queries\n        return q.size() - ans;\n    }\n};\n\n```
['Greedy', 'C', 'Sorting', 'Heap (Priority Queue)']