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 []\nstruct cmp {\n    bool operator()(const int& a, const int& b) const {\n        return a > b;\n    }\n};\n\nclass Solution {\npublic:\n    int n = 0;\n    int mx = 0;\n    vector<vector<int>> dp;\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& qs) {\n        n = nums.size();\n        int m = qs.size();\n        dp.resize(n);\n        for (auto& q : qs)\n        {\n            int l = q[0];\n            int r = q[1];\n            dp[l].push_back(r);\n        }\n        multiset<int, cmp> set;\n\n        vector<int> arr(n + 1, 0);\n        int cur = 0;\n        int cnt = 0;\n        for (int i = 0; i < n; i++)\n        {\n            for (auto r : dp[i])\n            {\n                set.insert(r);\n            }\n            int a = nums[i];\n            cur += arr[i];\n            auto iter = set.begin();\n            int d = a - cur;\n            for (int x = 0; x < d; x++)\n            {\n                if (set.empty()) break;\n                int y = *iter;\n                if (y < i) return -1;\n                arr[y + 1]--;\n                iter = set.erase(iter);\n                cnt++;\n                cur++;\n            }\n            // cout << i << "," << cnt << "," << cur << "," << set.size() << endl;\n            if (cur < a) return -1;\n            \n        }\n        return m - cnt;\n    }\n};\n```
['C++']