Logo
(追記) (追記ここまで)

32080번 - Merge Not Sort 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB99605257.778%

문제

You are currently researching the Merge Sort algorithm. Merge Sort is a sorting algorithm that is based on the principle of Divide and Conquer. It works by dividing an array into two subarrays of equal length, sorting each subarrays, then merging the sorted subarrays back together to form the final sorted array.

You are particularly interested in the merging routine. Common merge implementation will combine two subarrays by iteratively comparing their first elements, and move the smaller one to a new merged array. More precisely, the merge algorithm can be presented by the following pseudocode.

Merge(A[1..N], B[1..N]):
 C = []
 i = 1
 j = 1
 while i ≤ N AND j ≤ N:
 if A[i] < B[j]:
 append A[i] to C
 i = i + 1
 else:
 append B[j] to C
 j = j + 1
 while i ≤ N:
 append A[i] to C
 i = i + 1
 while j ≤ N:
 append B[j] to C
 j = j + 1
 return C

During your research, you are keen to understand the behaviour of the merge algorithm when arrays $A$ and $B$ are not necessarily sorted. For example, if $A = [3, 1, 6]$ and $B = [4, 5, 2],ドル then $\text{Merge}(A, B) = [3, 1, 4, 5, 2, 6]$.

To further increase the understanding of the merge algorithm, you decided to work on the following problem. You are given an array $C$ of length 2ドル \cdot N$ such that it is a permutation of 1ドル$ to 2ドル \cdot N$. Construct any two arrays $A$ and $B$ of the same length $N,ドル such that $\text{Merge}(A, B) = C,ドル or determine if it is impossible to do so.

입력

The first line consists of an integer $N$ (1ドル ≤ N ≤ 1000$).

The following line consists of 2ドル \cdot N$ integers $C_i$. The array $C$ is a permutation of 1ドル$ to 2ドル \cdot N$.

출력

If it is impossible to construct two arrays $A$ and $B$ of length $N$ such that $\text{Merge}(A, B) = C,ドル then output -1.

Otherwise, output the arrays $A$ and $B$ in two lines. The first line consists of $N$ integers $A_i$. The second line consists of $N$ integers $B_i$. If there are several possible answers, output any of them.

제한

예제 입력 1

3
3 1 4 5 2 6

예제 출력 1

3 1 6
4 5 2

The solution $A = [3, 1, 4]$ and $B = [5, 2, 6]$ is also correct.

예제 입력 2

4
1 2 3 4 5 6 7 8

예제 출력 2

2 3 5 7
1 4 6 8

The solution $A = [1, 2, 3, 4]$ and $B = [5, 6, 7, 8]$ is also correct.

예제 입력 3

2
4 3 2 1

예제 출력 3

-1

힌트

출처

ICPC > Regionals > Asia Pacific > Indonesia > Jakarta > The 2023 ICPC Asia Jakarta Regional Contest E번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /