#FT0000035. Khôi phục hoán vị (Restore Permutation)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Khôi phục hoán vị (Restore Permutation)
Restore Permutation
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
A hidden permutation contains every integer from through exactly once.
For each position , you are given , the sum of the values at earlier positions with strictly smaller values: both and must hold. If no earlier element is smaller, the sum is zero.
Recover the complete permutation from . The input is guaranteed to describe exactly one valid permutation.
Input
- Line 1: integer , the permutation length.
- Line 2: integers in position order.
Output
Print the permutation elements on one line, separated by spaces.
Subtasks
Subtask 1 (20 points):
- ; for all ; corresponds to a valid permutation of .
Subtask 2 (30 points):
- ; for all ; corresponds to a valid permutation of .
Subtask 3 (50 points):
- ; for all ; corresponds to a valid permutation of .
Examples
Examples 1
Input
5
0 1 1 1 10
Output
1 4 3 2 5
Explanation
For , the first sum is . At positions , only the earlier value is smaller, so each sum is . At position , all four earlier values are smaller and . This exactly reproduces the input.
Examples 2
Input
3
0 0 0
Output
3 2 1
Explanation
In the decreasing order , no earlier value is smaller than the current value, so all three sums are zero.
Because every permutation value is positive, any earlier smaller value would make the corresponding sum positive. Since all three sums are zero, the permutation must be strictly decreasing. With values 1, 2, and 3, the only possible order is .