BEATS 100% USERS || VIDEO EXPLANATION || EASY EXPLANATION || C++
Intuition\n Describe your first thoughts on how to solve this problem. \nVIDEO EXPLANATION - https://youtu.be/RVhEpnVX0jE \n# Approach\n Describe your approach 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nVIDEO EXPLANATION - https://youtu.be/RVhEpnVX0jE \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        // SORTING the queries\n        sort(queries.begin(),queries.end());\n\n        // STORING the queries\n        priority_queue<int> requiredQueries;\n        priority_queue<int, vector<int>, greater<int>>  chosenQueries;\n\n        int ans = 0; // to store the min no of queries\n        int n = nums.size();\n        int j = 0;\n\n        for(int i=0;i<n;i++){\n            // iterate through queries & consider those having val equal to i\n            while(j<queries.size() && queries[j][0]==i){\n                requiredQueries.push(queries[j][1]);\n                j++;\n            }\n\n            //REMOVE the size of already chosen queries from nums[i]\n            nums[i]-=chosenQueries.size();\n\n            while(nums[i]>0 && !requiredQueries.empty() && requiredQueries.top()>=i){\n                ans++;\n                chosenQueries.push(requiredQueries.top());\n                // REMOVAL of used queries\n                requiredQueries.pop();\n                nums[i]--;\n            }\n\n            if(nums[i]>0) return -1; // queries are not enough to make nums as zero array so returning -1\n\n            // REMOVAL of unwanted / eliminated queries\n            while(!chosenQueries.empty() && chosenQueries.top()<=i){\n                chosenQueries.pop();\n            }\n        }\n\n        return queries.size()-ans;\n    }\n};\n```
['C++']