Priority_queue and Ordered_set 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 []\n#include <bits/stdc++.h>\n#include <ext/pb_ds/assoc_container.hpp>\n#include <ext/pb_ds/tree_policy.hpp>\nusing namespace std;\nusing namespace __gnu_pbds;\ntemplate<class T>\nusing ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;\ntemplate<class T>\nusing ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries)\n    {\n        ordered_multiset<int> st;\n        sort(queries.begin(),queries.end(),[&](vector<int> &a, vector<int> &b){\n            return a[0] < b[0];\n        });\n        int cnt = 0;\n        int j = 0;\n        priority_queue<pair<int,int>> pq;\n        for(int i = 0; i < nums.size(); i++)\n        {\n            while(j < queries.size() && queries[j][0] <= i)\n            {\n                pq.push({queries[j][1],queries[j][0]});\n                j++;\n            }\n            int on_right = st.size() - st.order_of_key(i);\n            int val = nums[i]-on_right;\n            while(val > 0)\n            {\n                if(pq.empty() || (pq.top().first < i))\n                {\n                    return -1;\n                }\n                cnt++;\n                st.insert(pq.top().first);\n                val--;\n                pq.pop();\n            }\n        }\n        return queries.size()-cnt;\n    }\n};\n```
['C++']