A Strange Exhibit
Time limit2sMemory limit512 MB
Given the inversion counts of every window of length k in an unknown permutation of 1..n, reconstruct any valid permutation.
- Level
Hard8 of 10
- Topics
- Implementation, Greedy, Brute force, Combinatorics
- Solved
- No attempts yet
Problem
A new exhibit recently arrived at the exhibition of strange devices. It generates a random permutation of the numbers from to , scans it, and prints numbers on its screen. The -th of these numbers is the number of inversions in the segment of the generated permutation from position to position .
Recall that an inversion in a permutation is any pair of indices such that and p\[i] > p\[j]\].
Besides the screen, the exhibit has two knobs. The first sets , the length of the permutation, and the second sets . A visitor named Vasya turned the knobs and saw numbers on the screen. Now he wants to figure out which permutation the strange device generated. Help him.
Input
The first line contains two positive integers and (, , ). The second line contains the numbers printed by the device. The device is guaranteed to work correctly, and at least one permutation can produce these numbers.
Output
Print numbers separated by spaces: the permutation generated by the device. If several permutations are possible, print any one of them.