Order
InterviewTime limit1sMemory limit128 MB
Recover the permutation from counts of smaller previous elements, printing IMPOSSIBLE when the counts allow no permutation.
- Level
Medium5 of 10
- Topics
- Simulation, Math
- Solved
- No attempts yet
Problem
There is a sequence made up of distinct integers. It is a permutation that uses each integer from to exactly once, so for every and .
From we can build a new sequence , where is the number of elements among those that come before , namely , that are smaller than .
For example, if and , then .
Given a sequence , write a program that recovers the original sequence . If an corresponding to exists, it is uniquely determined, but for some inputs no such exists. For example, if and , then no corresponds to this .
Input
Input is read from standard input. The first line contains the number of test cases . Each test case consists of two lines: the first line contains the length of the sequence (), and the second line contains the integers of the sequence , separated by spaces.
Output
For each test case, print the sequence corresponding to the given on one line, with its numbers separated by spaces. If cannot be recovered from , print IMPOSSIBLE on that line instead.