✅Clean & Best Code🌟 || 💯MinPriority_Queue || ⚡HashSet
\n# Complexity\n\n- Time complexity:\nO(nlogn)   //Insertion in a PQ is O(log n)\n\n- Space complexity:\nO(n)\n\n\n# Code\n## PLease Upvote if it helps\uD83E\uD
\n# Complexity\n```\n- Time complexity:\nO(nlogn)   //Insertion in a PQ is O(log n)\n\n- Space complexity:\nO(n)\n```\n\n# Code\n## PLease Upvote if it helps\uD83E\uDD17\n```\nclass Solution {\npublic:\n    vector<long long> unmarkedSumArray(vector<int>& nums, vector<vector<int>>& q) {\n        int n = nums.size(), m = q.size();\n        vector<long long> ans(m);\n        long tot_sum = 0, prefix = 0;\n        unordered_set<int> marked;\n        using p = pair<int, int>;\n        priority_queue<p, vector<p>, greater<p>> pq;\n        for(int i = 0 ; i < n ; i++){\n            pq.push({nums[i], i});\n            tot_sum += nums[i];\n        }\n        for(int i = 0 ; i < m ; i++){\n            auto vec = q[i];\n            int x = vec[0], k = vec[1];\n            if(!marked.contains(x)){\n                marked.insert(x);\n                prefix += nums[x];\n            }\n            while(pq.size() && k){\n                auto [val, ind] = pq.top();\n                if(!marked.contains(ind)){\n                    prefix += val;\n                    k--;\n                    marked.insert(ind);\n                }\n                pq.pop();\n            }\n            ans[i] = tot_sum - prefix;\n        }\n        return ans;\n    }\n};\n```
['Heap (Priority Queue)', 'Prefix Sum', 'Ordered Set', 'C++']