Joining Arrays
Time limit4sMemory limit512 MB
Find the lexicographically smallest length-k array that splits into a non-empty subsequence of A and a non-empty subsequence of B, with positions interleaved.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Greedy, String
- Solved
- No attempts yet
Problem
Consider two arrays of integers and . The -join of and is the lexicographically smallest array of length that can be split into two non-empty subsequences, where the first is a subsequence of and the second is a subsequence of .
Formally, you need to find the array for which there exist two non-empty index sequences and , and two index sequences and , such that:
- For each and , we have .
- For each , we have .
- For each , we have .
For example, if , , and , their -join is (the subsequence from the first array is , and the subsequence from the second array is ).
For two given arrays and and an integer , find their -join .
Input
The first line contains , the length of array ().
The second line contains integers , the elements of ().
The third line contains , the length of array ().
The fourth line contains integers , the elements of ().
The last line contains the integer ().
Output
Output the -join of the given arrays.