🔥minHeap + simulation | Clean Code | C++ |
Code\n\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        long long sum = 0;\n      
# Code\n```\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& queries) {\n        long long sum = 0;\n        sum = accumulate(nums.begin(), nums.end(), 0LL);\n        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> minHeap;\n        for (int i = 0; i < nums.size(); i++)\n        {\n            minHeap.push({nums[i], i});\n        }\n        \n        vector<bool> marked(nums.size(), false);\n        \n        vector<long long> res;\n        for (auto q: queries)\n        {\n            if (marked[q[0]] == false)\n                sum -= nums[q[0]];\n            \n            marked[q[0]] = true;\n            while (!minHeap.empty() && q[1]--)\n            {\n                if (marked[minHeap.top().second] == false)\n                {\n                    sum -= minHeap.top().first;\n                    marked[minHeap.top().second] = true;\n                }\n                else\n                {\n                    q[1]++;\n                }\n                minHeap.pop();\n            }\n            \n            res.push_back(sum);\n        }\n        \n        return res;\n    }\n};\n```
['C++']