P28397 [洛谷] [COCI2017-2018#5] Karte
提高-
题目描述

Problem Description

There are $N$ cards stacked together, with the $i$-th card having a number $a_i$ indicating that there are at least $a_i$ cards below it with incorrect information. If there are indeed at least $a_i$ cards below it with incorrect information, then the information on this card is correct; otherwise, it is incorrect. (We consider the card at the bottom to have $0$ incorrect cards below it.)

You need to rearrange the order of the cards such that exactly $K$ cards have incorrect information.

Input Format

The first line contains two positive integers $N$ and $K$ $(1 ≤ N ≤ 5 \times 10^5, 0 ≤ K ≤ N)$, representing the number of cards and the required number of cards with incorrect information, respectively.
The next $N$ lines each contain a number representing $a_i$ $(0 ≤ a_i ≤ 5 \times 10^5)$.

Output Format

If a rearrangement scheme does not exist, output -1. Otherwise, output the $N$ values of $a_i$ from top to bottom. If there are multiple solutions, output any one of them.

Sample Input and Output

Sample Input #1

4 2
1 2 2 3

Sample Output #1

2 3 1 2

Sample Input #2

5 3
2 1 3 0 3

Sample Output #2

3 3 0 1 2

Sample Input #3

6 4
0 2 5 2 0 1

Sample Output #3

-1

Notes

  • $30\%$ of the test cases have $N ≤ 16$.
  • Another $40\%$ of the test cases have $N ≤ 2000$.

Sample 2 Explanation:

  • The 5th card has a $2$ on it, but there are only $0$ incorrect cards below it, so it is incorrect.
  • The 4th card has a $1$ on it, and there is $1$ incorrect card below it (the 5th card), so it is correct.
  • The 3rd card has a $0$ on it, and there is $1$ incorrect card below it (the 5th card), so it is correct.
  • The 2nd card has a $3$ on it, but there are only $1$ incorrect card below it (the 5th card), so it is incorrect.
  • The 1st card has a $3$ on it, but there are only $2$ incorrect cards below it (the 5th and 2nd cards), so it is incorrect.

Thus, there are a total of $3$ incorrect cards.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
4 2 1 2 2 3
样例输出
2 3 1 2