Multiset with difference arrays
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    long long int maxRemoval(vector<int>& nums, vector<vector<int>>& Q) {\n        long long int n = nums.size();\n        multiset<pair<long long int,long long int>> m;\n        \n        vector<long long int> arr(n + 1 , 0);\n\n        \n        sort(Q.begin() , Q.end());\n        long long int ptr = 0;\n        long long int q = Q.size();\n        long long int ans = 0;\n        for(long long int i = 0; i < n; i++) {\n            while(ptr < q and Q[ptr][0] == i) {\n                m.insert({Q[ptr][1] , Q[ptr][0]});\n                ptr++;\n            }    \n            long long val = 0;\n            if(i) arr[i] += arr[i - 1];\n            val = arr[i];\n            if(val < nums[i]) {\n                long long int diff = nums[i] - val;\n                if(m.size() < diff) return -1;\n                for(long long int j = 0; j < diff; j++) {\n                    long long int r = m.rbegin() -> first;\n                    long long int l = m.rbegin() -> second;\n                    arr[i]++;\n                    arr[r + 1]--;\n                    m.erase(--m.end());\n                    ans++;\n                }\n            }\n            while(m.size() and m.begin() -> first <= i) {\n                m.erase(m.begin());\n            }\n        }\n        return q - ans;\n    }\n};\n```
['Greedy', 'C++']