minheap solution in c++ with explanation
Intuition\n Describe your first thoughts on how to solve this problem. \nwe need to find the k largest elements in the array and return them in order of there i
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nwe need to find the k largest elements in the array and return them in order of there indexes in the array\n# Approach\n<!-- Describe your approach to solving the problem. -->\nuse a minheap to find the largest k elements in the array. also store the indexes of elements in the heap. then use another minheap to sort the elements by there indexes.  \n# Complexity\n- Time complexity:O(NlogN)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:O(K)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> maxSubsequence(vector<int>& nums, int k) {\n        priority_queue<pair<int,int> , vector<pair<int,int>>,greater<pair<int,int>> > pq;\n\n        for(int i = 0; i < nums.size(); i++){\n            pq.push({nums[i],i});\n            if(pq.size() > k){\n                pq.pop();\n            }\n        }\n\n        priority_queue<pair<int,int> , vector<pair<int,int>>,greater<pair<int,int>> > temp;\n\n        while(!pq.empty()){\n            temp.push({pq.top().second,pq.top().first});\n            pq.pop();\n        }\n\n        vector<int> ans;\n        while(!temp.empty()){\n            ans.push_back(temp.top().second);\n            temp.pop();\n        }\n\n        return ans;\n    }\n};\n```
['Array', 'Heap (Priority Queue)', 'C++']