100% beat in all
Complexity\n- Time complexity: O(n log(n))\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \
# Complexity\n- Time complexity: O(n log(n))\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(n)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    static bool comp(vector<int>&a,vector<int>&b){\n        return a[0]<b[0];\n    }\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& q) {\n        sort(q.begin(),q.end(),comp);\n        vector<int>t(nums.size(),0);\n        priority_queue<int>l;\n        int tn=0;\n        int in=0;\n        for(int i=0;i<nums.size();i++){\n            nums[i]=max(0,nums[i]-tn);\n            while(in<q.size() && q[in][0]==i){\n                l.push(q[in][1]);\n                in++;\n            }\n            while(nums[i] && !l.empty() && l.top()>=i)nums[i]--,tn++,t[l.top()]++,l.pop();\n            if(nums[i])return -1;\n            tn-=t[i];\n        }\n        return l.size();\n    }\n};\n```
['C++']