luogu#P8278. 「MCOI-08」Fill In
「MCOI-08」Fill In
Background
$$\begin{aligned}\text{sdjvlajdiofjoiw{\color{1f1e33}n}eglaj}\\\text{pcji{\color{1f1e33}2}gweiruitowoeuri}\\\text{cnvak{\color{1f1e33}5}jflkjweirqoiru}\\\text{rrrwei{\color{1f1e33}f}dlskfjqfafdfaff}\\\text{nmslfjwiejfijlxkjfq{\color{1f1e33}b}el}\\\text{mmm{\color{1f1e33}b}fsfmkdfmksld}\\\text{erjf{\color{1f1e33}n}kerjkwerjkwjeri}\\\text{sdfafafaf{\color{1f1e33}r}fxvzxvzvzx}\end{aligned}$$Problem Description
Dream has an array of positive integers of length (). For , it satisfies .
He computed the prefix sum array , and it is guaranteed that in the original prefix sum array, for any , we have .
Now Tommy stole this array and replaced some elements of with . Given the current array , restore any valid . It can be proven that there is always at least one array that satisfies the requirements.
Input Format
This problem contains multiple test cases. The first line contains a positive integer , the number of test cases. Then follow test cases. For each test case:
The first line contains an integer .
The second line contains integers , representing the prefix sum sequence.
Output Format
For each test case:
Output one line with integers, representing one array that satisfies the requirements.
2
5
10 -1 20 -1 30
6
-1 -1 -1 -1 -1 -1
10 5 5 5 5
1 1 4 5 1 4
Hint
Explanation for Sample 1
The output sequence must satisfy the conditions:
- ;
- ;
- .
Constraints
For of the testdata, , and it is guaranteed that there exists at least one valid array .
- Subtask 1 (50 pts): For , ;
- Subtask 2 (30 pts): It is guaranteed that there does not exist an such that ;
- Subtask 3 (20 pts): No special restrictions.
Translated by ChatGPT 5