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

16043번 - Missing Gnomes 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB127767061.404%

문제

A family of n gnomes likes to line up for a group picture. Each gnome can be uniquely identified by a number 1..n written on their hat.

Suppose there are 5 gnomes. The gnomes could line up like so: 1, 3, 4, 2, 5.

Now, an evil magician will remove some of the gnomes from the lineup and wipe your memory of the order of the gnomes. The result is a subsequence, perhaps like so: 1, 4, 2.

He then tells you that if you ordered all permutations of 1..n in lexicographical order, the original sequence of gnomes is the first such permutation which contains the remaining subsequence. Your task is to find the original sequence of gnomes.

입력

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will begin with a line with two integers n and then m (1 ≤ m ≤ n ≤ 105), where n is the number of gnomes originally, and m is the number of gnomes remaining after the evil magician pulls his trick. Each of the next m lines will contain a single integer g (1 ≤ g ≤ n). These are the remaining gnomes, in order. The values of g are guaranteed to be unique.

출력

Output n lines, each containing a single integer, representing the first permutation of gnomes that could contain the remaining gnomes in order.

제한

예제 입력 1

5 3
1
4
2

예제 출력 1

1
3
4
2
5

예제 입력 2

7 4
6
4
2
1

예제 출력 2

3
5
6
4
2
1
7

힌트

출처

University > North American Invitational Programming Contest > NAIPC 2018 D번

Contest > Open Cup > 2017/2018 Season > Stage 16: Grand Prix of America D번

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

출처

대학교 대회

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

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