Prefix Suffix Min Max There is an array A A with integer elements of size n n. We create…
- User
Prefix Suffix Min Max There is an array A A with integer elements of size n n. We create another array B B where
B i B i
∑ j
1 i A j ∑ j=1 i A j
m a x { A 1 , A 2 , . . . . , A i } max{A 1 ,A 2 ,....,A i }
You are given this array B B and asked to find any valid array A A.
Note: For a given array B B solution always exists.
Input Format The first line of input will contain a single integer T T, denoting the number of test cases. Each test case consists of multiple lines of input. The first line of each test case contains an integer N N. The second line of each test case contains N N space-separated integers B 1 , B 2 , … , B N B 1 ,B 2 ,…,B N — the elements of array B B. Output Format For each test case, output on a new line N N space-separated integers A 1 , A 2 , … , A N A 1 ,A 2 ,…,A N — the elements of array A A.
Constraints 1 ≤ T ≤ 1000 1≤T≤1000 1 ≤ N ≤ 1 0 6 1≤N≤10 6
− 2 ⋅ 1 0 6 ≤ A i ≤ 2 ⋅ 1 0 6 −2⋅10 6 ≤A i ≤2⋅10 6
− 1 0 6 ≤ B i ≤ 1 0 6 −10 6 ≤B i ≤10 6
The sum of N N over all test cases won't exceed 1 0 6 10 6 . Sample 1: Input Output 3 3 0 -2 1 4 0 -1 -2 1 5 0 2 2 -4 -13 3 -2 4 3 -1 -1 3 4 2 0 -6 -9 Explanation: For testcase 1:
Let A A = [ 3 , − 2 , 4 ] [3,−2,4]
B 1 B 1
A 1 A 1
A 1 A 1
0 0
B 2 B 2
A 1 A 1 + A 2 A 2
max max( A 1 A 1 , A 2 A 2 ) = 1 1 - 3 3 = - 2 2
B 3 B 3
A 1 A 1 + A 2 A 2 + A 3 A 3
max max( A 1 A 1 , A 2 A 2 , A 3 A 3 ) = 5 5 - 4 4 = 1 1
- Assistant