My Solution
\n/**\n * Time Complexity: O(n + n_queries * log(n_queries))\n * Space Complexity: O(n + n_queries)\n * where `n` is the length of the vector `nums`\n */\nclass
```\n/**\n * Time Complexity: O(n + n_queries * log(n_queries))\n * Space Complexity: O(n + n_queries)\n * where `n` is the length of the vector `nums`\n */\nclass Solution {\n public:\n  int maxRemoval(const vector<int> &nums, vector<vector<int>> &queries) {\n    const int n = static_cast<int>(nums.size());\n    const int n_queries = static_cast<int>(queries.size());\n    sort(queries.begin(), queries.end());\n    priority_queue<int> pq;\n    int diffs[n + 1];\n    memset(diffs, 0, sizeof(diffs));\n    int used = 0;\n    for (int sum = 0, i_query = 0, i = 0; i < n; ++i) {\n      for (; i_query < n_queries && queries[i_query].front() < i + 1; ++i_query) {\n        pq.emplace(queries[i_query].back());\n      }\n      \n      sum += diffs[i];\n      while (sum < nums[i] && !pq.empty()) {\n        const int end = pq.top();\n        pq.pop();\n        if (end > i - 1) {\n          ++used;\n          ++sum;\n          --diffs[end + 1];\n        }\n      }\n      \n      if (sum < nums[i]) {\n        return -1;\n      }\n    }\n    return n_queries - used;\n  }\n};\n```
[]