C++
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 []\n#define PII pair<int, int> \n\nclass Compare {\n    public: \n        bool operator()(PII a, PII b) {\n            if(a.second < b.second) {\n                return true;\n            }\n            return false;\n        }\n};\n\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries) {\n        int i = 0, n = nums.size(), nq = queries.size();\n\n        sort(queries.begin(), queries.end());\n\n        priority_queue<PII, vector<PII>, Compare> myPq;\n\n        int count = 0, used = 0, qInd = 0;\n        unordered_map<int, int> endingCount;\n\n        for(i = 0; i < nums.size(); i++) {\n\n            while(qInd < nq && queries[qInd][0] == i) {\n                myPq.push({queries[qInd][0], queries[qInd][1]});\n                qInd++;\n            }\n\n            while(nums[i] > count) {\n                PII top;\n                if(!myPq.empty()) {\n                    top = myPq.top();\n                    myPq.pop();\n                } else {\n                    //cout<< "Queue got empty i:" << i << "count: " << count << \'\\n\';\n                    return -1;\n                }\n\n                if(top.second < i) {\n                    //cout << "The second: " << top.second << " is lesser than i: " << \'\\n\';\n                    return -1;\n                } \n\n                endingCount[top.second]++;\n                count++;\n            }\n\n            count -= endingCount[i];\n            used += endingCount[i];\n        }\n\n        return nq - used;\n    }\n};\n```
['C++']