Using sorting || C++ || Explained
First add elements and their index in a vector of pair format - {a[i],i}\nthen reverse sort them\nNow add first k elements in a temporary array of vector of pai
First add elements and their index in a vector of pair format - {a[i],i}\nthen reverse sort them\nNow add first k elements in a temporary array of vector of pair format - {i,a[i]}\nNow sort this temp and add elements to ans\n\nSpace - O(n) Because storing all the elements in another vector\nTime - O(n*log(n)) Because sorting is involved\n\n```\nclass Solution {\npublic:\n    \n    vector<int> maxSubsequence(vector<int>& a, int k) {\n        \n        int n = a.size();\n        \n        vector<pair<int,int>> v;\n        \n        for(int i = 0 ; i < n ; i++)\n            v.push_back({a[i],i});\n        \n        sort(begin(v),end(v));\n        reverse(begin(v),end(v));\n        \n        vector<pair<int,int>> t;\n        \n        for(int i = 0 ; i < k ; i++)\n            t.push_back({v[i].second,v[i].first});\n        \n        \n        sort(begin(t),end(t));\n        \n        vector<int> ans;\n        \n        for(int i = 0 ; i < k ; i++)\n            ans.push_back(t[i].second);\n        \n        return ans;\n    }\n};\n```
[]