[C++] Difference + Greedy
CODE:\n\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries) {       int n = nums.size(), T = queries.size();\n      
**CODE:**\n```\nclass Solution {\npublic:\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries) {       int n = nums.size(), T = queries.size();\n        // Prework 0:  \n        int a[n+10];\n        for (int i = 1; i <= n; i++) a[i] = nums[i-1];\n\n        // Prework 1:   Sort all queries\n        for (auto& e : queries) e[0]++, e[1]++;\n        sort(queries.begin(), queries.end(), [&](auto& l, auto& r){ return l[0]==r[0]?l[1]<r[1]:l[0]<r[0]; });\n\n        // Max-Heap \n        priority_queue<int> que;\n\n\n        int d[n+10];    \n        memset(d, 0, sizeof(d));\n\n        int ans = 0, pos = 0;\n        for (int i = 1; i <= n; i++) { \n            // Difference Array  \n            d[i] += d[i-1];\n\n            // Push [i, r] into the heap \n            while (pos < T && queries[pos][0] == i) que.push(queries[pos++][1]);\n\n            // Greedy:  Choose the interval that covers the furthest position currently\n            while (!que.empty() && d[i] < a[i]) {\n                int e = que.top(); que.pop();           \n                if (e < i) { ans++; continue; }         \n                \n                d[i]++;\n                d[e+1]--;\n            }\n\n            if (d[i] < a[i]) return -1;\n        }\n\n        return ans + que.size() + (T - pos);\n    }\n};\n```
[]