#P14865. [ICPC 2020 Yokohama R] Secrets of Legendary Treasure
[ICPC 2020 Yokohama R] Secrets of Legendary Treasure
题目描述
Finally, you have discovered the document with two integer sequences, the final keys to unlocking the secret of the legendary treasure! The ink on the document, however, has faded so much that some of the numbers in the sequences are too faint to read. Fortunately, you have heard of a legend on the characteristics of the key sequences that (1) the numbers in the two sequences are all different and are between 1 and the sum of the lengths of the two sequences, and (2) both sequences are arranged in ascending order.
Please restore the original sequences from the readable numbers and the legend.
输入格式
The input consists of a single test case of the following format.
$$\begin{aligned} &n \ m \\ &a_1 \ \dots \ a_n\\ &b_1 \ \dots \ b_m \\ \end{aligned}$$The first line consists of two integers () and (). They are the lengths of the two sequences and , respectively. The second line describes the sequence . Each is either 0, meaning that the -th element of is unreadable, or a positive integer meaning that the element reads . The third line describes the sequence in the same fashion.
输出格式
Print a pair of restored sequences and in two lines. The sequences should be consistent with the input and the legendary characteristics of the sequences.
The elements of the sequence should be printed in the first line, separated by a space character. Then the elements of the sequence should be printed in the second line, in the same manner.
If there are multiple possibilities, print any one of such pairs. At least one sequence pair consistent with the input and conforming to the legend is guaranteed to exist.
3 3
0 0 0
4 0 0
1 2 3
4 5 6
6 7
0 5 0 0 0 13
0 0 3 0 8 0 12
4 5 7 10 11 13
1 2 3 6 8 9 12
提示
Note that there are other acceptable outputs for the second sample input, such as the one with the positions of 6 and 7 exchanged.