AtCoder Regular Contest 178
A
Good Permutation 2
AtCoder
⌀ 438
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given a positive integer $N$ and a sequence of $M$ positive integers $A = (A_{1}, A_{2}, \dots, A_{M})$.

翻译中…

Here, all elements of $A$ are distinct integers between $1$ and $N$, inclusive.

翻译中…

A permutation $P = (P_{1}, P_{2}, \dots, P_{N})$ of $(1, 2, \dots, N)$ is called a good permutation when it satisfies the following condition for all integers $i$ such that $1 \leq i \leq M$:

翻译中…
  • No contiguous subsequence of $P$ is a permutation of $(1, 2, \dots, A_{i})$.
翻译中…

Determine whether a good permutation exists, and if it does, find the lexicographically smallest good permutation.

翻译中…

What is lexicographical order? A sequence $S = (S_1, S_2, \ldots, S_{|S|})$ is said to be lexicographically smaller than a sequence $T = (T_1, T_2, \ldots, T_{|T|})$ if one of the following conditions holds. Here, $|S|$ and $|T|$ denote the lengths of $S$ and $T$, respectively. $|S| \lt |T|$ and $(S_1, S_2, \ldots, S_{|S|}) = (T_1, T_2, \ldots, T_{|S|})$. There exists an integer $1 \leq i \leq \min\lbrace |S|, |T| \rbrace$ such that both of the following hold: $(S_1, S_2, \ldots, S_{i-1}) = (T_1, T_2, \ldots, T_{i-1})$. $S_i$ is smaller than $T_i$ (as a number).

翻译中…

Constraints

翻译中…
  • $1 \leq M \leq N \leq 2 \times 10^{5}$
  • $1 \leq A_{i} \leq N$
  • All elements of $A$ are distinct.
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N M
A_{1} A_{2} \cdots A_{M}

翻译中…

Output

翻译中…

If a good permutation does not exist, print -1.

翻译中…

If it exists, print the lexicographically smallest good permutation, separated by spaces.

翻译中…

样例

Input #1
4 1
2
Output #1
1 3 2 4
For example, $(4, 2, 1, 3)$ is not a **good permutation** because it contains $(2, 1)$ as a contiguous subsequence. Other non-**good permutations** are $(1, 2, 3, 4)$ and $(3, 4, 2, 1)$. Some **good permutations** are $(4, 1, 3, 2)$ and $(2, 3, 4, 1)$. Among these, the lexicographically smallest one is $(1, 3, 2, 4)$, so print it separated by spaces.
Input #2
5 3
4 3 2
Output #2
1 3 4 5 2
Examples of **good permutations** include $(3, 4, 1, 5, 2)$, $(2, 4, 5, 3, 1)$, and $(4, 1, 5, 2, 3)$. Examples of non-**good permutations** include $(1, 2, 5, 3, 4)$, $(2, 3, 4, 1, 5)$, and $(5, 3, 1, 2, 4)$.
Input #3
92 4
16 7 1 67
Output #3
-1
If a **good permutation** does not exist, print `-1`.
Input #4
43 2
43 2
Output #4
-1
题目信息
题号
arc178_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。