Set
A set allows us to track whether an element was marked and not, and retrieve smallest elements.\n\n(with a priority queue, we need to track marked elements sepa
A set allows us to track whether an element was marked and not, and retrieve smallest elements.\n\n(with a priority queue, we need to track marked elements separately).\n\n**C++**\n```cpp\nvector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n    vector<long long> res;\n    long long sum = accumulate(begin(nums), end(nums), 0LL);\n    set<array<int, 2>> s;\n    for (int i = 0; i < nums.size(); ++i)\n        s.insert({nums[i], i});\n    for (const auto &q : queries) {\n        auto it = s.find({nums[q[0]], q[0]});\n        if (it != end(s)) {\n            sum -= nums[q[0]];\n            s.erase(it);\n        }\n        for (int k = q[1]; k && !s.empty(); --k) {\n            sum -= (*begin(s))[0];\n            s.erase(begin(s));\n        }\n        res.push_back(sum);\n    }\n    return res;\n}\n```
['C']