[Solution] Confusing Concatenations CodeChef Solution
Problem
Chef initially had two non-empty arrays and , where both arrays contain distinct elements. Moreover, there is no common element in the arrays and .
Chef forms another array from the arrays and using the following process :
- Let denote the leftmost element of array and denote the leftmost element of array .
- If is smaller than , delete from and append it to the end of .
- If is smaller than , delete from and append it to the end of .
- If either array or becomes empty, append all the remaining elements of the other array to the end of .
Chef forgot the arrays and but remembers the array . Find any two valid non-empty arrays and that will yield the given array . If it is not possible, print .
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of multiple lines of input.
- The first line of each test case contains a space-separated integer — the number of elements in array .
- The next line contains space-separated integers denoting the elements of the array .
👇👇👇👇👇
Output Format
For each test case, if a solutions exists, print any two valid arrays and along with their lengths respectively . For example, if and , then print it as :
Explanation:
Test case : We have and .
- Move : and . Since , we delete and append it to . Thus, and .
- Move : and . Since , we delete and append it to . Thus, and .
- Move : and . Since , we delete and append it to . Thus, and .
- Now, since is empty, append all elements of to . Thus, .
Test case : It can be shown that there exist no valid non-empty arrays and .
No comments:
Post a Comment