sorting, priority_queue, c++
solved after contest;\nhere we make individual element zero\nand first we consider the longest end point that constains current point greedily\n# Complexity\n- 
solved after contest;\nhere we make individual element zero\nand first we consider the longest end point that constains current point greedily\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    // to check if it possible make zero array with all queries\n    bool ispos(vector<int>& nums, vector<vector<int>>& qu){\n        int n = nums.size();\n        vector<int> diff(n + 1, 0);\n        for(auto v : qu){\n            diff[v[0]]--;\n            diff[v[1] + 1]++;\n        }\n        for(int i = 1; i <= n; i++){\n            diff[i] += diff[i - 1];\n        }\n        for(int i = 0; i < n; i++){\n            if(nums[i] + diff[i] > 0) return false;\n        }\n        return true;\n    }\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& qu) {\n        //to the queries in order we sort\n        sort(qu.begin(), qu.end());\n        if(!ispos(nums, qu)) return -1;\n        int n = nums.size(), q = qu.size(), used = 0;\n        priority_queue<pair<int, int>> pq;\n        vector<int> diff(n + 1, 0);\n        for(int i = 0, j = 0; i < n; i++){\n            if(i != 0){\n                diff[i] += diff[i - 1];\n            }\n            int curr = nums[i];\n            curr += diff[i];\n            //pushing all queries thats constains i\n            while(j < q and qu[j][0] <= i){\n                pq.push({qu[j][1], qu[j++][0]});\n            }\n            while(curr > 0 and !pq.empty()){\n                auto [r, l] = pq.top();\n                pq.pop();\n                // the query wont effect current element\n                if(r < i){\n                    continue;\n                }\n                used++;\n                curr -= 1;\n                diff[i] -= 1;\n                diff[r + 1] += 1;\n            }\n        }\n        return q - used;\n    }\n};\n```
['C++']