Share C++ 72ms with simple comments
vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {\n        const int size1 = nums1.size();\n        const int size2 = nums2.size();\n      
    vector<int> maxNumber(vector<int>& nums1, vector<int>& nums2, int k) {\n        const int size1 = nums1.size();\n        const int size2 = nums2.size();\n        if (size1 + size2 < k) return vector<int>();\n        vector<int> res(k, 0);\n        vector<vector<int>> dp1(k+1, vector<int>()), dp2(k+1, vector<int>());\n        getDp(nums1, k, dp1);\n        getDp(nums2, k, dp2);\n        for (int i = 0; i <= min(k, size1); i++) {\n            int j = k - i;\n            vector<int> temp_res(k, 0);\n            myMerge(dp1[i].begin(), dp1[i].end(), dp2[j].begin(), dp2[j].end(), temp_res.begin());\n            if (j <= size2 && compareVector(temp_res, res)) {\n                res = temp_res;\n            }\n        }\n        return res;\n    }\n    \n    template <class container>\n    bool compareVector ( container vec1, container vec2)\n        {\n          typename container::iterator first1 = vec1.begin(), last1 = vec1.end();\n          typename container::iterator first2 = vec2.begin(), last2 = vec2.end();\n          while (first1 != last1 && first2 != last2) {\n            if (*first1 > *first2)\n              return true;\n            else if (*first1 < *first2) return false;\n            ++first1; ++first2;\n          }\n          if (first1 == last1) return false;\n          else return true;\n        }\n        \n    void getDp(vector<int> nums, int k, vector<vector<int>> &dp) {\n          while (nums.size() > k) {\n                int j = 0;\n                for (; j < nums.size() - 1; ++j) {\n                    if (nums[j] < nums[j + 1]) {\n                        nums.erase(nums.begin() + j); \n                        break;\n                    }\n                }\n                if (j == nums.size() - 1) nums.erase(nums.begin() + j); \n           }\n           dp[nums.size()] = nums;\n           const int size1 = nums.size();\n           for (int i = k; i > 0; i--) {\n            if (i >= size1) continue; \n            else {\n                dp[i] = dp[i+1];\n                int j = 0;\n                const int size_dp = dp[i].size();\n                for (; j < size_dp - 1; ++j) {\n                    if (dp[i][j] < dp[i][j + 1]) {\n                        dp[i].erase(dp[i].begin() + j); \n                        break;\n                    }\n                }\n                if (j == size_dp - 1) dp[i].erase(dp[i].begin() + j); \n            }\n            \n        }\n    }\n    template <class InputIterator1, class InputIterator2, class OutputIterator>\n    OutputIterator myMerge (InputIterator1 first1, InputIterator1 last1,\n                        InputIterator2 first2, InputIterator2 last2,\n                        OutputIterator result)\n    {\n      while (true) {\n        if (first1==last1) return std::copy(first2,last2,result);\n        if (first2==last2) return std::copy(first1,last1,result);\n        if (*first2 > *first1) *result++ = *first2++;\n        else if (*first2 < *first1) *result++ = *first1++;\n        else { // *first1 == *first2\n            auto pos1 = first1, pos2 = first2;\n            while (true) {\n                int f1 = (++pos1 != last1) ? *(pos1) : INT_MIN;\n                int f2 = (++pos2 != last2) ? *(pos2) : INT_MIN;\n                if (f1 > f2) { *result++ = *first1++; break;}\n                else if (f1 < f2) {*result++ = *first2++; break;}\n            }\n        }\n      }\n    }
['Dynamic Programming']