Python Two Different Solutions Sorting/Heap
Complexity\n- Time complexity: O(nlogn)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n
# Complexity\n- Time complexity: $$O(nlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```python []\nclass Solution(object):\n    def unmarkedSumArray(self, nums, queries):\n        """\n        :type nums: List[int]\n        :type queries: List[List[int]]\n        :rtype: List[int]\n        """\n        n=len(nums)\n        marked=[None]*n\n        s_nums=sorted([ (nums[idx],idx) for idx in range(n)])\n        res=[]\n        s=sum(nums)\n        i=0\n        for idx,k in queries:\n            if not marked[idx]:\n                s-=nums[idx]\n                marked[idx]=True\n            while i<n and k:\n                if not marked[s_nums[i][1]]:\n                    s-=s_nums[i][0]\n                    k-=1\n                    marked[s_nums[i][1]]=True\n                i+=1\n            if s==0:\n                break\n            res.append(s)\n        return res\n```\n# Complexity\n- Time complexity: $$O(nlogn+qlogn)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n# Code\n```python []\nclass Solution(object):\n    def unmarkedSumArray(self, nums, queries):\n        """\n        :type nums: List[int]\n        :type queries: List[List[int]]\n        :rtype: List[int]\n        """\n        heap=[ (nums[idx],idx)for idx in range(len(nums))]\n        heapify(heap)\n        res=[0]*len(queries)\n        s=sum(nums)\n        for idx in range(len(queries)):\n            query=queries[idx]\n            if nums[query[0]]>0:\n                s-=nums[query[0]]\n                nums[query[0]]*=-1\n            k=query[1]\n            while heap and k>0:\n                val=heappop(heap)\n                if nums[val[1]]>0:\n                    s-=nums[val[1]]\n                    nums[val[1]]*=-1 \n                    k-=1\n            if s==0:\n                break\n            res[idx]=s\n        return res\n```
['Python']