C++ O(n log K) || Min. Heap
Connect with me on LinkedIn: https://www.linkedin.com/in/abhay5349singh/\n\n\nclass Solution {\npublic:\n\n    vector<int> maxSubsequence(vector<int>& a, int k)
**Connect with me on LinkedIn**: https://www.linkedin.com/in/abhay5349singh/\n\n```\nclass Solution {\npublic:\n\n    vector<int> maxSubsequence(vector<int>& a, int k) {\n        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq; // {element,idx}\n        \n        int n=a.size();\n        for(int i=0;i<n;i++){\n            if(pq.size()<k){\n                pq.push({a[i],i});\n            }else if(pq.size()==k && pq.top().first<a[i]){ // storing max k elements in priority queue\n                pq.pop();\n                pq.push({a[i],i});\n            }\n        }\n        \n        vector<pair<int,int>> sub;\n        while(pq.size()>0){\n            int val=pq.top().first, idx=pq.top().second;\n            pq.pop();\n            \n            sub.push_back({idx,val}); // storing index to print in correct order\n        }\n        sort(sub.begin(),sub.end());\n        \n        vector<int> ans;\n        for(int i=0;i<k;i++) ans.push_back(sub[i].second);\n        \n        return ans;\n    }\n};\n```
['Heap (Priority Queue)', 'C++']