C++ Simple Solution using Multiset
\nvector<int> maxSubsequence(vector<int>& nums, int k) {\n        typedef pair<int,int> pii;\n\t\t//we maintain a multiiset of pair [not a set coz our array has
```\nvector<int> maxSubsequence(vector<int>& nums, int k) {\n        typedef pair<int,int> pii;\n\t\t//we maintain a multiiset of pair [not a set coz our array has duplicates too ]\n\t\t//having value as {element,index}\n        multiset<pii> st;\n        int n = size(nums);\n        \n\t\t//we iterate over the array to find k largest elements along with their indices\n        for(int i=0;i<n;i++)\n        {\n            if(size(st) < k) st.insert({nums[i],i});\n            else \n            {\n                auto it = st.begin();\n                if((*it).first < nums[i])\n                {\n                    st.erase(it);\n                    st.insert({nums[i],i});\n                }\n            }\n        }\n        \n\t\t//now we make a set to store the index of previously calculated values in \n\t\t//non-decreasing form\n        set<int> idx;\n        for(auto &ele : st) idx.insert(ele.second);\n        \n\t\t//the only thing remains now is to push the elements into\n\t\t//our answer vector and return it\n        vector<int> res;\n        for(auto &ele : idx) res.push_back(nums[ele]);\n        \n        return res;\n    }\n```\n\n**Time Complexity :** O(n * log k)\n**Space Complexity :** O(k)
['Ordered Set']