Python | Heap
Code\n\nfrom heapq import heapify, heappush, heappop\nclass Solution:\n    def unmarkedSumArray(self, nums: List[int], queries: List[List[int]]) -> List[int]:\n
# Code\n```\nfrom heapq import heapify, heappush, heappop\nclass Solution:\n    def unmarkedSumArray(self, nums: List[int], queries: List[List[int]]) -> List[int]:\n        n = len(nums)\n        T = sum(nums)\n        marked = [False]*n\n        h = [(num,i) for i,num in enumerate(nums)]\n        heapify(h)\n        res = []\n        for i, k in queries:\n            if not marked[i]:\n                T -= nums[i]\n                marked[i] = True\n            while h and k:\n                if marked[h[0][1]]:\n                    heappop(h)\n                else:\n                    num, i = heappop(h)\n                    T -= nums[i]\n                    k -= 1\n                    marked[i] = True\n            res.append(T)\n        return res\n```
['Python3']