It can't be Medium (Two Priority Queue + Segment Tree)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\nFirst Priority Queue is used for Finding all Intervals containing this in
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\nFirst Priority Queue is used for Finding all Intervals containing this indexed element and Second Priority Queue is used for finding the "Furthest Interval"(NOT LONGEST) containting this non-zero array value.\nSegment tree is used for Updating all the elements of the intervals even those elements which we are not currenty inspecting and Via Find operation of segment tree we can find the current value of this index before starting priority_queue operations\n\n# Complexity\n- Time complexity: O(N * log 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#define ll int\n#define pb push_back\n    vector<ll> a;\n    ll seg_tree[400001][2];\n    // Building segment tree\n    void Build(ll l, ll r, ll node) {\n        if (l == r) {\n            seg_tree[node][0] = a[l];\n            seg_tree[node][1] = 0;\n            return;\n        }\n        ll mid = (l + r) / 2;\n        Build(l, mid, (2 * node) + 1);\n        Build(mid + 1, r, (2 * node) + 2);\n        seg_tree[node][0] =\n            max(seg_tree[(2 * node) + 1][0], seg_tree[(2 * node) + 2][0]);\n        seg_tree[node][1] = 0;\n        return;\n    }\n    // Query Update\n    void Update(ll l, ll r, ll node, ll left, ll right) {\n        if ((l > right) || (r < left)) {\n            return;\n        }\n        if ((l >= left) && (r <= right)) {\n            seg_tree[node][0]--;\n            seg_tree[node][1]++;\n            return;\n        }\n        ll mid = (l + r) / 2;\n        Update(l, mid, (2 * node) + 1, left, right);\n        Update(mid + 1, r, (2 * node) + 2, left, right);\n        seg_tree[node][0] =\n            max(seg_tree[(2 * node) + 1][0], seg_tree[(2 * node) + 2][0]) -\n            seg_tree[node][1];\n    }\n    // Find Range_Wise Max\n    ll Find(ll l, ll r, ll node, ll left, ll right) {\n        if ((l > right) || (r < left)) {\n            return 0;\n        }\n        if ((l >= left) && (r <= right)) {\n            return seg_tree[node][0];\n        }\n        ll mid = (l + r) / 2;\n        ll x = Find(l, mid, (2 * node) + 1, left, right);\n        ll y = Find(mid + 1, r, (2 * node) + 2, left, right);\n        ll z = max(x, y) - seg_tree[node][1];\n        return z;\n    }\n    int maxRemoval(vector<int>& nums, vector<vector<int>>& queries) {\n        a = nums;\n        ll n = a.size();\n        priority_queue<pair<ll, ll>> p, q;\n        for (ll i = 0; i < queries.size(); i++) {\n            ll x = -queries[i][0], y = queries[i][1];\n            p.push({x, y});\n        }\n        Build(0, n - 1, 0);\n        ll ans = 0;\n        for (ll i = 0; i < a.size(); i++) {\n            ll x = Find(0, n - 1, 0, 0, i);\n            if (x <= 0) {\n                continue;\n            }\n            if(!p.empty()){\n            auto w = p.top();\n            ll y = -w.first, z = w.second;\n            while (y <= i) {\n                if (z < i) {\n                    p.pop();\n                    ans++;\n                } else {\n                    p.pop();\n                    q.push({z, -y});\n                }\n                if (p.empty()) {\n                    break;\n                }\n                w = p.top();\n                y = -w.first;\n                z = w.second;\n            }\n            }\n            while (x > 0 && (!q.empty())) {\n                auto w = q.top();\n                ll y = -w.second;\n                ll z = w.first;\n                if (z < i) {\n                    break;\n                } else {\n                    x--;\n                    Update(0, n - 1, 0, y, z);\n                    q.pop();\n                }\n            }\n            if (x > 0) {\n                ans = -1;\n                break;\n            }\n        }\n        if (ans == -1) {\n            return ans;\n        }\n        ll z = (p.size()) + (q.size());\n        ans += z;\n        return ans;\n    }\n};\n```
['C++']