[CF2290F] 还原排列 (Reconstruct Permutation)
Problem Statement
For a permutation of length , define an array as follows:
Initially, for all . For every pair of values with such that appears to the left of in , perform:
- subtract from ;
- add to .
Note that is indexed by the values themselves, not by positions.
Given , reconstruct a permutation that produces this array , or report -1 if no such permutation exists. It can be proved that if such a permutation exists, it is unique.
Input
The first line contains () — the number of test cases.
Each test case consists of () on the first line, and integers () on the second line.
It is guaranteed that the sum of over all test cases does not exceed .
Output
For each test case, print -1 if no valid permutation exists; otherwise print integers .
Example
5
3
0 -1 1
1
0
2
1 1
4
-2 1 -1 2
3
-1 0 1
2 3 1
1
-1
3 1 4 2
-1
Note
- Constraints: , , , .
- Source: Codeforces 2290F · Reconstruct Permutation