python heap
Intuition\n Describe your first thoughts on how to solve this problem. \nThe idea if to keep order of the max numbers and get the max sum at the same time\n# Ap
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe idea if to keep order of the max numbers and get the max sum at the same time\n# Approach\n<!-- Describe your approach to solving the problem. -->\nuse min heap to track the largest number inside k values, use i to track all indexes\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\nO(nlogn)\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\nO(n)\n# Code\n```\nclass Solution:\n    def maxSubsequence(self, nums: List[int], k: int) -> List[int]:\n        min_heap = []\n        for i, n in enumerate(nums):\n            heappush(min_heap, (n, i))\n            if len(min_heap) > k:\n                heappop(min_heap)\n        min_heap.sort(key = lambda x: x[1])\n        return [i[0] for i in min_heap]\n```
['Python3']