#P6891. Monotonic Sequence Construction
Monotonic Sequence Construction
Monotonic Sequence Construction
You are given two sequences \(A\) and \(B\) of length \(2n\). Your task is to construct a sequence \(C\) of length \(2n\) that satisfies the following conditions:
- For \(1 \le i \le 2n\), \(C_i\) is chosen from either \(A_i\) or \(B_i\).
- You must choose exactly \(n\) elements from \(A\) and exactly \(n\) elements from \(B\).
- The resulting sequence \(C\) must be non-decreasing, i.e., \(C_1 \le C_2 \le \cdots \le C_{2n}\).
If there are multiple valid sequences \(C\), you only need to output one of them.
Note: All formulas are given in LaTeX format.
inputFormat
The input contains three lines:
- The first line contains a single integer \(n\).
- The second line contains \(2n\) integers, representing the sequence \(A\): \(A_1, A_2, \ldots, A_{2n}\).
- The third line contains \(2n\) integers, representing the sequence \(B\): \(B_1, B_2, \ldots, B_{2n}\).
outputFormat
Output a single line containing \(2n\) integers separated by spaces, which form a valid non-decreasing sequence \(C\) satisfying the conditions. If there are multiple answers, output any one.
sample
1
1 3
2 2
1 2