QOJ.ac

QOJ

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100 ハック可能 ✓

#17246. Apparently Make UTPC

統計

Ti vengono date le sequenze di interi positivi $A = (A_1, A_2, \dots, A_X)$, $B = (B_1, B_2, \dots, B_Y)$ e $C = (C_1, C_2, \dots, C_Z)$ di lunghezze rispettivamente $X$, $Y$ e $Z$. Qui vale $X \le Y \le Z$.

Vuoi riordinare gli elementi di $C$ in modo tale che la sequenza risultante contenga sia $A$ che $B$ come sottosequenze contigue.

Determina se è possibile raggiungere questo obiettivo. Se è possibile, trova la sequenza $C$ lessicograficamente più piccola dopo il riordinamento.

Ti vengono dati $T$ casi di test. Risolvi ciascuno di essi.

Input

L'input viene fornito dallo Standard Input nel seguente formato:

$$\begin{aligned} &T \\ &\text{case}_1 \\ &\text{case}_2 \\ &\vdots \\ &\text{case}_T \end{aligned}$$

Ogni caso viene fornito nel seguente formato:

$$\begin{aligned} &X \ Y \ Z \\ &A_1 \ A_2 \ \dots \ A_X \\ &B_1 \ B_2 \ \dots \ B_Y \\ &C_1 \ C_2 \ \dots \ C_Z \end{aligned}$$

  • Tutti i valori in input sono interi.
  • $1 \le T \le 10^5$
  • $1 \le X \le Y \le Z \le 2 \times 10^5$
  • $1 \le A_i \le Z$
  • $1 \le B_i \le Z$
  • $1 \le C_i \le Z$
  • La somma di $X + Y + Z$ su tutti i casi di test in un singolo input è al massimo $4 \times 10^5$.

Output

Stampa $T$ righe. La $i$-esima riga deve contenere -1 se l'obiettivo non può essere raggiunto per l'$i$-esimo caso di test, oppure la sequenza $C$ riordinata lessicograficamente più piccola se può essere raggiunto.

Esempi

Input 1

3
2 2 4
4 3
2 1
4 3 2 1
2 3 4
4 3
3 2 1
4 3 2 1
3 3 3
1 1 1
2 2 2
3 3 3

Output 1

2 1 4 3
4 3 2 1
-1

Note

  • Nel primo esempio, le possibili sequenze riordinate per $C$ sono $(2, 1, 4, 3)$ e $(4, 3, 2, 1)$. Stampa $(2, 1, 4, 3)$, che è la più piccola lessicograficamente.
  • Nel secondo esempio, l'unica sequenza riordinata possibile per $C$ è $(4, 3, 2, 1)$. Stampa $(4, 3, 2, 1)$.
  • Nel terzo esempio, l'obiettivo non può essere raggiunto. Stampa -1.

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#2918EditorialOpenHashc20262110View
#1405EditorialOpen题解jianglyView

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.