CF1547C.Pair Programming

普及-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.

It's known that they have worked together on the same file for n+mn + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already kk lines written in the file.

Every minute exactly one of them does one of two actions: adds a new line to the end of the file or changes one of its lines.

Monocarp worked in total for nn minutes and performed the sequence of actions [a1,a2,…,an][a_1, a_2, \dots, a_n]. If ai=0a_i = 0, then he adds a new line to the end of the file. If ai>0a_i \gt 0, then he changes the line with the number aia_i. Monocarp performed actions strictly in this order: a1a_1, then a2a_2, ..., ana_n.

Polycarp worked in total for mm minutes and performed the sequence of actions [b1,b2,…,bm][b_1, b_2, \dots, b_m]. If bj=0b_j = 0, then he adds a new line to the end of the file. If bj>0b_j \gt 0, then he changes the line with the number bjb_j. Polycarp performed actions strictly in this order: b1b_1, then b2b_2, ..., bmb_m.

Restore their common sequence of actions of length n+mn + m such that all actions would be correct — there should be no changes to lines that do not yet exist. Keep in mind that in the common sequence Monocarp's actions should form the subsequence [a1,a2,…,an][a_1, a_2, \dots, a_n] and Polycarp's — subsequence [b1,b2,…,bm][b_1, b_2, \dots, b_m]. They can replace each other at the computer any number of times.

Let's look at an example. Suppose k=3k = 3. Monocarp first changed the line with the number 22 and then added a new line (thus, n=2, a=[2,0]n = 2, \: a = [2, 0]). Polycarp first added a new line and then changed the line with the number 55 (thus, m=2, b=[0,5]m = 2, \: b = [0, 5]).

Since the initial length of the file was 33, in order for Polycarp to change line number 55 two new lines must be added beforehand. Examples of correct sequences of changes, in this case, would be [0,2,0,5][0, 2, 0, 5] and [2,0,0,5][2, 0, 0, 5]. Changes [0,0,5,2][0, 0, 5, 2] (wrong order of actions) and [0,5,2,0][0, 5, 2, 0] (line 55 cannot be edited yet) are not correct.

Monocarp 和 Polycarp 正在学习新的编程技巧。现在他们决定尝试结对编程。

已知他们共同在同一文件上工作了 n+mn + m 分钟。每分钟恰好有其中一人对文件执行一次修改操作。在开始之前,文件中已有 kk 行内容。

每分钟恰好有一人执行以下两种操作之一:在文件末尾添加一行,或修改文件中的某一行。

Monocarp 总共工作了 nn 分钟,执行的操作序列为 [a1,a2,…,an][a_1, a_2, \dots, a_n]。若 ai=0a_i = 0,表示他在文件末尾添加一行;若 ai>0a_i \gt 0,表示他修改第 aia_i 行。Monocarp 严格按此顺序执行操作:先 a1a_1,再 a2a_2,……,最后 ana_n。

Polycarp 总共工作了 mm 分钟,执行的操作序列为 [b1,b2,…,bm][b_1, b_2, \dots, b_m]。若 bj=0b_j = 0,表示他在文件末尾添加一行;若 bj>0b_j \gt 0,表示他修改第 bjb_j 行。Polycarp 也严格按此顺序执行操作:先 b1b_1,再 b2b_2,……,最后 bmb_m。

请还原一个长度为 n+mn + m 的共同操作序列,使得所有操作均合法——即不允许修改尚不存在的行。注意,在该共同序列中,Monocarp 的操作必须构成子序列 [a1,a2,…,an][a_1, a_2, \dots, a_n],而 Polycarp 的操作必须构成子序列 [b1,b2,…,bm][b_1, b_2, \dots, b_m]。两人可在任意时刻交替使用计算机,切换次数不限。

我们来看一个例子。设 k=3k = 3。Monocarp 先修改第 22 行,然后添加一行(即 n=2, a=[2,0]n = 2,\: a = [2, 0])。Polycarp 先添加一行,再修改第 55 行(即 m=2, b=[0,5]m = 2,\: b = [0, 5])。

由于文件初始长度为 33,为使 Polycarp 能修改第 55 行,必须在此之前至少添加两行。此时,合法的操作序列示例包括 [0,2,0,5][0, 2, 0, 5] 和 [2,0,0,5][2, 0, 0, 5]。而不合法的序列如 [0,0,5,2][0, 0, 5, 2](违反 Monocarp 操作顺序)和 [0,5,2,0][0, 5, 2, 0](此时第 55 行尚不存在,无法修改)。

输入格式

The first line contains an integer tt (1≤t≤10001 \le t \le 1000). Then tt test cases follow. Before each test case, there is an empty line.

Each test case contains three lines. The first line contains three integers kk, nn, mm (0≤k≤1000 \le k \le 100, 1≤n,m≤1001 \le n, m \le 100) — the initial number of lines in file and lengths of Monocarp's and Polycarp's sequences of changes respectively.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (0≤ai≤3000 \le a_i \le 300).

The third line contains mm integers b1,b2,…,bmb_1, b_2, \dots, b_m (0≤bj≤3000 \le b_j \le 300).

第一行包含一个整数 tt(1≤t≤10001 \le t \le 1000)。随后是 tt 个测试用例。每个测试用例之前有一空行。

每个测试用例包含三行。第一行包含三个整数 kk、nn、mm(0≤k≤1000 \le k \le 100,1≤n,m≤1001 \le n, m \le 100),分别表示文件初始的行数,以及 Monocarp 和 Polycarp 的修改操作序列的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(0≤ai≤3000 \le a_i \le 300)。

第三行包含 mm 个整数 b1,b2,…,bmb_1, b_2, \dots, b_m(0≤bj≤3000 \le b_j \le 300)。

输出格式

For each test case print any correct common sequence of Monocarp's and Polycarp's actions of length n+mn + m or -1 if such sequence doesn't exist.

对于每个测试用例,输出任意一个长度为 n+mn + m 的 Monocarp 与 Polycarp 行动的公共序列;如果不存在这样的序列,则输出 -1。

输入输出样例

  • 输入#1

    5
    
    3 2 2
    2 0
    0 5
    
    4 3 2
    2 0 5
    0 6
    
    0 2 2
    1 0
    2 3
    
    5 4 4
    6 0 8 0
    0 7 0 9
    
    5 4 1
    8 7 8 0
    0

    输出#1

    2 0 0 5 
    0 2 0 6 5 
    -1
    0 6 0 7 0 8 0 9
    -1

输入解题思路,AI测评打分。不知道怎么写?

首页