#P14865. [ICPC 2020 Yokohama R] Secrets of Legendary Treasure

    ID: 14784 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划 DP2020Special JudgeICPC横浜

[ICPC 2020 Yokohama R] Secrets of Legendary Treasure

Description

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.

Input Format

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 nn (1n1001 \le n \le 100) and mm (1m1001 \le m \le 100). They are the lengths of the two sequences AA and BB, respectively. The second line describes the sequence AA. Each aia_i is either 0, meaning that the ii-th element of AA is unreadable, or a positive integer 1ain+m1 \le a_i \le n + m meaning that the element reads aia_i. The third line describes the sequence BB in the same fashion.

Output Format

Print a pair of restored sequences AA and BB in two lines. The sequences should be consistent with the input and the legendary characteristics of the sequences.

The elements of the sequence AA should be printed in the first line, separated by a space character. Then the elements of the sequence BB 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

Hint

Note that there are other acceptable outputs for the second sample input, such as the one with the positions of 6 and 7 exchanged.