CPP Simple Greedy solution.
\n\nclass Solution {\npublic:\n    vector<int> calc(vector<int> &v,int k,int n) {\n        vector<int> v1;\n        // IF I replace the current top or not.\n   
```\n\nclass Solution {\npublic:\n    vector<int> calc(vector<int> &v,int k,int n) {\n        vector<int> v1;\n        // IF I replace the current top or not.\n        int i=-1,j,ind=-1,ans=-1;\n        while(k) {\n            j=i+1;ind=-1;ans=-1;\n            while(j<n&&n-j>=k) {\n                if(v[j]>ans) {\n                    ans=v[j];\n                    ind=j;\n                }\n                j++;\n            }\n            i=ind;\n            v1.push_back(ans);\n            k--;\n        }\n        return v1;\n    }\n    vector<int> merge(vector<int> &v1,vector<int> &v2,int n,int m) {\n        vector<int> v;\n        if(n>m) {\n            swap(v1,v2);\n            swap(n,m);\n        }\n        int i=0,j=0;\n        while(i<n && j<m) {\n            if(v1[i]>v2[j]) {\n                v.push_back(v1[i]);\n                i++;\n            }\n            else if(v1[i]<v2[j]) {\n                v.push_back(v2[j]);\n                j++;\n            }\n            else {\n                int k=i+1,l=j+1,f=1;\n                while(k<n && l<m) {\n                    if(v1[k]>v2[l]) { f=0;break; }\n                    else if(v1[k]<v2[l]) { f=1;break;}\n                    k++;\n                    l++;\n                }\n                \n                if(f==0||l==m) { v.push_back(v1[i++]); }\n                else     { v.push_back(v2[j++]); }\n            }\n        }\n        while(i<n) { v.push_back(v1[i]);i++; }\n        while(j<m) { v.push_back(v2[j]);j++; }\n        return v;\n    }\n    int comp(vector<int> v1,vector<int> v2,int k) {\n        for(int i=0;i<k;i++) { \n            if(v1[i]!=v2[i]) return v1[i]>v2[i];\n        }\n        return 0;\n    }\n    vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {\n        int n=nums1.size(),m=nums2.size();\n        // If I have to chose k greatest elements.\n        // from a vector. how you are going to pick up.\n        // this task is awesome.\n        vector<int> ans(k,-1);\n        for(int i=0;i<=min(n,k);i++) {\n            int r=k-i;\n            if(r<=m) { \n                vector<int> v1=calc(nums1,i,n),v2=calc(nums2,r,m);\n                vector<int> x=merge(v1,v2,i,r);\n                if(comp(x,ans,k)>0) ans=x;\n            }\n        }\n        return ans;\n    }\n};\n\n```
[]