C++ || Brute Force & Optimized solution
Brute Force\n\n static bool comp(pair<int,int> a, pair<int,int>b){\n        return a.second < b.second;\n    }\n    vector<int> maxSubsequence(vector<int>& nums
**Brute Force**\n```\n static bool comp(pair<int,int> a, pair<int,int>b){\n        return a.second < b.second;\n    }\n    vector<int> maxSubsequence(vector<int>& nums, int k) {\n        if(nums.size()==0){\n            return {};\n        }\n        vector<pair<int,int>> result;\n        vector<int> res;\n        \n        priority_queue<pair<int,int>, vector<pair<int,int>>> pq;\n        \n        for(int i=0; i<nums.size(); ++i){\n            pq.push({nums[i],i});\n        }\n        \n        while(k){\n            result.push_back(pq.top());\n            pq.pop();\n            k--;\n        }\n        sort(result.begin(), result.end() , comp);\n        for(auto &p : result){\n            res.push_back(p.first);\n        }\n        \n        return res;\n    }\n```\n\n<hr>\n\n**Optimized **\n```\n    vector<int> maxSubsequence(vector<int>& nums, int k) {\n        vector<pair<int,int>> vec;\n        vector<int> res;\n        for(int i=0; i<nums.size(); ++i){\n            vec.push_back({nums[i], i});\n        }\n        nth_element(begin(vec), begin(vec)+k, end(vec), greater<pair<int,int>>()); // seperating greater & smaller element with (begin + k) pivot\n        \n        sort(begin(vec), begin(vec)+k, [](const auto &a, const auto &b){ return a.second < b.second; });// sort first k elements by indices;\n        \n        for(int i=0; i<k; ++i){ // k length\n            res.push_back(vec[i].first);\n        }\n        return res;\n    }
['C', 'C++']