Team selection

시간 제한6초메모리 제한1024 MB

요약
두 팀장이 번갈아 남은 선수 중 k번째를 고를 때, 각 팀이 뽑은 선수를 순서대로 출력한다.
난이도

쉬움10점 중 3점

유형
배열, 구현
정답자
아직 제출이 없습니다

문제

Two team leaders get to assemble their teams by choosing team members among a set of players that are numbered from 11 to NN. The leaders take turns, each picking the kkth player among the remaining ones, according to their ideas of which one of the remaining players would be the best addition to their teams.

Given the choices of the two leaders (the first team leader starts first), please compute the list of players in each team.

입력

The input consists of three lines. The first line contains the single integer NN. The second line contains N/2N/2 space-separated integers a_1,a_2,…,a_N/2a\_1, a\_2, \dots , a\_{N/2} representing the choices of the first team leader: during the (2k−1)(2k - 1)th turn, the first leader chose the a_ka\_kth remaining player. The third line contains N/2N/2 space-separated integers b_1,b_2,…,b_N/2b\_1, b\_2, \dots , b\_{N/2} representing the choices of the second team leader: during the 2k2kth turn, the second leader chose the b_kb\_kth remaining player.

출력

The output should contain two lines, each containing N/2N/2 space-separated integers. The first line should contain the list x_1,x_2,…,x_N/2x\_1, x\_2, \dots , x\_{N/2} of the players chosen to become members of the first team, in the order they were chosen: the player x_kx\_k was chosen during the (2k−1)(2k - 1)th turn. The second line should contain the list y_1,y_2,…,y_N/2y\_1, y\_2, \dots , y\_{N/2} of the players chosen to become members of the second team, in the order they were chosen: the player y_ky\_k was chosen during the 2k2kth turn.

제한

  • 2≤N≤4,000,0002 \le N \le 4\\, 000\\, 000
  • NN is a multiple of 22
  • the choices of the team leaders are valid: at each step, they are between 11 and the number of remaining players (inclusive).

예제1

  1. 예제 1

    입력
    4
    1 1
    2 1
    
    예상 출력
    1 2
    3 4