[C++] Priority queue
To efficiently process the queries that finish the latest:\n1. Use a priority queue to store the queries, prioritizing those that finish the latest.\n1. Apply a
To efficiently process the queries that finish the latest:\n1. Use a priority queue to store the queries, prioritizing those that finish the latest.\n1. Apply a line sweep algorithm to keep track of the number of queries ending at each point:\n    - For each query\'s end time, add \u22121 to represent the decrement in the active query count.\n    - This approach ensures that the queries with later end times are processed first, while the line sweep manages the active query counts dynamically.\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries) {\n        int n = nums.size(), qsz = queries.size();\n        sort(queries.begin(), queries.end());\n        priority_queue<int>pq;\n        vector<int>sweep(n + 1, 0);\n        int ind = 0, cs = 0;\n        for (int i = 0; i < n; i++) {\n            cs += sweep[i];\n            while (ind < qsz && queries[ind][0] <= i) {\n                pq.push(queries[ind][1]);\n                ind++;\n            }\n            while (cs < nums[i] && !pq.empty() && pq.top() >= i) {\n                cs++;\n                sweep[pq.top() + 1]--;\n                pq.pop();\n            }\n            if (cs < nums[i])\n                return -1;\n        }\n        return pq.size();\n    }\n};\n```
['C++']