Only sort
Intuition\n Describe your first thoughts on how to solve this problem. \nSort the entire array in decreasing order while maintaining it\'s index. The first k el
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nSort the entire array in decreasing order while maintaining it\'s index. The first k elements will give the maximum sum so again sort first k elements in increasing order of the index and return it.\n\n# Complexity\n- Time complexity: $$O(n*log(n))$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<int> maxSubsequence(vector<int>& nums, int k) {\n        int n = nums.size();\n        vector<pair<int,int>> v(n);\n        vector<int> ans(k);\n        for(int i=0; i<n; ++i) v[i] = {nums[i],i};\n        sort(rbegin(v),rend(v));\n        sort(begin(v),begin(v)+k,[](auto a,auto b){return a.second < b.second;});\n        for(int i=0; i<k; ++i) ans[i] = v[i].first;\n        return ans;\n    }\n};\n```
['Array', 'Sorting', 'C++']