Simple Greedy Solution O(nlogn)
IntuitionTo solve this problem, the initial thought was to select the top k largest elements from the array while preserving their original order.Approach
Creat
# Intuition  
To solve this problem, the initial thought was to select the top `k` largest elements from the array while preserving their original order.

# Approach  
- Create a copy of the input array and sort it.  
- Extract the `k` largest elements and store their frequencies in a map.  
- Iterate through the original array, adding elements to the result if they are part of the selected largest elements, maintaining the original order.  
- Stop when `k` elements are added.  

# Complexity  
- **Time complexity:** $$O(n \log n)$$ for sorting and $$O(n)$$ for the iteration — overall $$O(n \log n)$$.  
- **Space complexity:** $$O(n)$$ for the auxiliary map and vector.

# Code
```cpp []
class Solution {
public:
    vector<int> maxSubsequence(vector<int>& nums, int k) {
        vector<int> temp=nums;
        sort(temp.begin(),temp.end());
        map<int,int> mpp;
        int n=nums.size();
        for(int i=0;i<k;i++){
            mpp[temp[n-i-1]]++;
        }
        vector<int> ans;
        int ind=0;
        while(ind<n){
            if(ans.size()==k) break;
            if(mpp.count(nums[ind])){
                ans.push_back(nums[ind]);
                mpp[nums[ind]]--;
                if(mpp[nums[ind]]==0) mpp.erase(nums[ind]);
            }
            ind++;
        }
        return ans;
    }
};
```
['Array', 'Hash Table', 'Sorting', 'C++']