| Codeforces Round 1114 (Div. 3) |
|---|
| Finished |
Yousef has a secret array $$$a$$$ of $$$n$$$ strictly positive integers.
For each element $$$a_i$$$, its shadow $$$b_i$$$ is the sum of all elements in $$$a$$$ that are strictly smaller than $$$a_i$$$. Formally:
$$$$$$b_i = \sum_{\substack{1 \le j \le n\\ a_j \lt a_i}} a_j$$$$$$
You are given the shadow array $$$b$$$. Your task is to reconstruct the lexicographically smallest valid array $$$a$$$ consisting of strictly positive integers that satisfies the above condition. If no such array exists, output $$$-1$$$.
The first line contains an integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases.
The first line of each test case contains an integer $$$n$$$ ($$$1 \le n \le 2 \cdot 10^5$$$) — the size of the array.
The second line of each test case contains $$$n$$$ integers $$$b_1, b_2, \dots, b_n$$$ ($$$0 \le b_i \le 2 \cdot 10^{14}$$$) — the shadow array.
It is guaranteed that the sum of $$$n$$$ over all test cases does not exceed $$$2 \cdot 10^5$$$.
For each test case, output $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^{18}$$$) — the lexicographically smallest valid array $$$a$$$ that satisfies the condition. If no valid array exists, output $$$-1$$$ instead.
81050 4 0 4 1434 0 030 0 030 1 141 1 1 170 4 4 4 4 4 950 0 0 3 3
12 5 2 5 63 2 21 1 11 2 2-1-11 1 1 2 2
In the first test case, the answer is $$$a = [1]$$$. Since there is only one element, there are no strictly smaller elements, so its shadow is $$$0$$$. Thus $$$a=[1]$$$ is valid. It is also lexicographically smallest, because the only allowed values are positive integers, and $$$1$$$ is the smallest possible.
In the second test case, the answer is $$$a = [2,5,2,5,6]$$$:
Therefore the shadow array is exactly $$$b = [0,4,0,4,14]$$$.
In the third test case, the shadow array for $$$a = [3, 2, 2]$$$ is calculated as follows:
The resulting shadow array is $$$b = [4, 0, 0]$$$, which matches the input.
| Name |
|---|


