/
実行時間制限: 2 sec / メモリ制限: 1024 MiB
配点 : 500 点
問題文
長さ N の非負整数列 A=(A_1,A_2,\ldots,A_N) が与えられます。
A の要素を並べ替えて得られる数列 B=(B_1,B_2,\ldots,B_N) であって、すべての i=1,2,\ldots,N について次の条件を満たすものが存在するか判定し、存在する場合は そのような数列を 1 つ構成してください。
- B_i は、1\le j\lt i かつ B_j\lt B_i を満たす整数 j の個数に等しい。
制約
- 1\le N\le 5\times 10^5
- 0\le A_i\lt N
- 入力される数値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N A_1 A_2 \ldots A_N
出力
条件を満たす数列 B が存在しない場合、No と出力せよ。
存在する場合、以下の形式で Yes と数列 B を出力せよ。
Yes B_1 B_2 \ldots B_N
条件を満たす数列が複数存在する場合は、どれを出力してもよい。
入力例 1
4 3 0 1 0
出力例 1
Yes 0 1 0 3
出力された数列は A を並べ替えたものです。 i=1,2,3,4 に対し、B_i の左側にある B_i より小さい要素の個数は、それぞれ 0,1,0,3 個で、B_i と等しいです。
入力例 2
3 0 2 2
出力例 2
No
値 2 より小さい要素は 1 個しかないため、どのように並べ替えても条件を満たせません。
入力例 3
7 4 1 6 0 4 3 1
出力例 3
Yes 0 1 1 3 4 4 6
出力された数列は A を並べ替えたものです。 i=1,2,\ldots,7 に対し、B_i の左側にある B_i より小さい要素の個数は、それぞれ 0,1,1,3,4,4,6 個で、B_i と等しいです。
Score : 500 points
Problem Statement
You are given a length-N sequence of non-negative integers A=(A_1,A_2,\ldots,A_N).
Determine whether there exists a sequence B=(B_1,B_2,\ldots,B_N) that is a permutation of A that satisfies the following condition for every i=1,2,\ldots,N, and construct one such sequence if it exists.
- B_i is equal to the number of integers j satisfying 1 \le j < i and B_j < B_i.
Constraints
- 1 \le N \le 5 \times 10^5
- 0 \le A_i < N
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N A_1 A_2 \ldots A_N
Output
If there is no sequence B satisfying the condition, output No.
If one exists, output Yes and a sequence B in the following format:
Yes B_1 B_2 \ldots B_N
If multiple sequences satisfy the condition, you may output any of them.
Sample Input 1
4 3 0 1 0
Sample Output 1
Yes 0 1 0 3
The output sequence is a permutation of A. For i=1,2,3,4, the number of elements to the left of B_i that are smaller than B_i is 0,1,0,3, respectively, which equals B_i.
Sample Input 2
3 0 2 2
Sample Output 2
No
Since there is only one element smaller than the value 2, no permutation satisfies the condition.
Sample Input 3
7 4 1 6 0 4 3 1
Sample Output 3
Yes 0 1 1 3 4 4 6
The output sequence is a permutation of A. For i=1,2,\ldots,7, the number of elements to the left of B_i that are smaller than B_i is 0,1,1,3,4,4,6, respectively, which equals B_i.