C++ | Faster than 100% | Priority Queue | With Comments
\nclass Solution {\npublic:\n    vector<int> maxSubsequence(vector<int>& nums, int k) {\n        //Using a Priority Queue to store pair\n        priority_queue<
```\nclass Solution {\npublic:\n    vector<int> maxSubsequence(vector<int>& nums, int k) {\n        //Using a Priority Queue to store pair\n        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;\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        // Store the k elements \n        vector<pair<int, int>> ans;\n        while(!pq.empty()){\n            auto x = pq.top();\n            pq.pop();\n            ans.push_back({x.second , x.first});\n        }\n        \n        //Sort k element based on original index\n        sort(ans.begin(), ans.end());\n        \n        //Return the ans\n        vector<int> finalAns;\n        for(auto x : ans){\n            finalAns.push_back(x.second);\n        }\n        return finalAns;\n    }\n};\n\n// Time : O(nlogn) + O(k) + O(klogk) + O(k)\n```
['Heap (Priority Queue)']