#P8023. [ONTAK2015] Tasowanie

[ONTAK2015] Tasowanie

Problem Description

Given two digit sequences AA and BB, merge AA and BB with a two-way merge to obtain a new digit sequence TT. Find the lexicographically smallest TT.

Input Format

The first line contains an integer nn, the length of AA.

The second line contains nn integers, representing AA.

The third line contains an integer mm, the length of BB.

The fourth line contains mm integers, representing BB.

Output Format

Output one line with n+mn + m positive integers, representing the lexicographically smallest TT.

6
1 2 3 1 2 4
7
1 2 2 1 3 4 3
1 1 2 2 1 2 3 1 2 3 4 3 4

Hint

For 100%100\% of the testdata, 1n,m2×1051 \leq n, m \leq 2 \times 10^5, and each number in AA and BB is a positive integer not exceeding 10310^3.

  • On 2023.9.10, two sets of hack testdata were added.

Translated by ChatGPT 5