Elegant Python Solution using Sets and Queue.
Intuition\n1) Use sets for marked.\n2) Use tuples to store the index while sorting.\n3) Use queue on the sorted array to find the smallest numbers.\n\n# Approac
# Intuition\n1) Use sets for marked.\n2) Use tuples to store the index while sorting.\n3) Use queue on the sorted array to find the smallest numbers.\n\n# Approach\n1) Calculate the totalSum and store it in a variable. Initialize ans for result.\n2) Initialize the set marked to store the marked items.\n3) Convert nums into a tuple of (i, nums[i]) where you preserve the index.\n4) Duplicate the array and sort in based on the 1st index.\n5) Iterate through the Query.\n6) Add nums[index] to marked if not already marked. Update totalSum.\n7) Using a while loop, pop and mark the smallest elements from the sorted array. Update totalSum.\n8) Append the totalSum at the end of the iteration to ans.\n9) Return ans.\n\n\n# Complexity\n- Time complexity:\nO(n log n)\n\n- Space complexity:\nO(n)\n\n# Code\n```\nfrom collections import deque\nclass Solution:\n    def unmarkedSumArray(self, nums, queries):\n        totSum = sum(nums)\n        marked = set()\n        nums = [(i,nums[i]) for i in range(len(nums))]\n        nums2 = sorted(nums, key = lambda x:x[1])\n        nums2 = deque(nums2)\n        ans = []\n        for idx, k in queries:\n            if nums[idx] not in marked:\n                marked.add(nums[idx])\n                totSum -= nums[idx][1]\n            while k and nums2:\n                item = nums2.popleft()\n                if item not in marked:\n                    k -= 1\n                    marked.add(item)\n                    totSum -= item[1]\n            ans.append(totSum)\n        return ans\n```
['Queue', 'Ordered Set', 'Python3']