题目描述
Consider an array A consisting of N positive elements. The frequency array of A is the array B of size N such that B_{i} = frequency of element A_{i} in A.
For example, if A = [4, 7, 4, 11, 2, 7, 7], the frequency array B = [2, 3, 2, 1, 1, 3, 3].
You have lost the array A, but fortunately you have the array B.
Your task is to construct the lexicographically smallest array A such that:
1≤ A_{i} ≤ 10^{5};
The frequency array of A is equal to B.
If no such array A exists, print -1.
Note: Array X is lexicographically smaller than array Y, if X_{i} < Y_{i}, where i is the first index where X and Y differ.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer N — the size of the array.
- The next line contains $N space-separated integers - B_{1}, B_{2}, \ldots, B_{N}$, the frequency array.
------ Output Format ------
For each test case, output on $a new line, N space separated integers - A_{1}, A_{2}, \ldots, A_{N}$, the lexicographically smallest array A. If no such array A exists, print -1.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ B_{i} ≤ 10^{5}$
- The sum of $N$ over all test cases won't exceed $10^{6}$.
----- Sample Input 1 ------
5
5
2 3 3 3 2
5
1 1 1 1 1
5
5 5 5 5 5
3
1 2 4
8
1 3 2 3 2 2 2 3
----- Sample Output 1 ------
1 2 2 2 1
1 2 3 4 5
1 1 1 1 1
-1
1 2 3 2 3 4 4 2
----- explanation 1 ------
Test case $1$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 2, 2, 1]$. The element $A_{1}$ and $A_{5}$ have frequency $2$ while $A_{2}, A_{3},$ and $A_{4}$ have frequency $3$.
Test case $2$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 2, 3, 4, 5]$. Each element in $A$ has frequency $1$.
Test case $3$: The lexicographically smallest array $A$ having the given frequency array $B$ is $A = [1, 1, 1, 1, 1]$. Each element in $A$ has frequency $5$.
Test case $4$: No possible array $A$ exists having the given frequency array.
输入格式
见题面
输出格式
见题面