Beautiful solution ;)
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```cpp []\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries) {\n        sort(queries.begin(), queries.end());\n\n        priority_queue<vector<int>> pq; // {end, start} of query\n        multiset<vector<int>> aqs; // {end, start} of query.\n        \n\n        int num_active_queries = 0;\n\n        int i = 0, j = 0;\n\n        int ans = 0;\n\n        while (i < nums.size()) {\n            while(!aqs.empty() && (*aqs.begin())[0] < i) {\n                // end reached.\n                aqs.erase(aqs.find(*aqs.begin()));\n                num_active_queries --;\n            }\n\n            while(j < queries.size()) {\n                if(queries[j][0] <= i && queries[j][1] >= i) {\n                    pq.push({queries[j][1], queries[j][0]});\n                } else if(queries[j][0] > i) {\n                    break;\n                }\n                j ++;\n            }\n\n            // cout << i << " " << j << " " << num_active_queries << endl;\n\n            while(nums[i] > num_active_queries && !pq.empty()) {\n                auto it = pq.top();\n                pq.pop();\n                if(it[0] >= i) {\n                    aqs.insert(it);\n                    ans ++;\n                    num_active_queries ++;\n                }\n            }\n\n            if(nums[i] > num_active_queries) {\n                return -1;\n            }\n            i ++;\n        }\n\n        return queries.size() - ans;\n    }\n};\n```
['C++']