1739B.md (1235B)
1 Source: https://codeforces.com/problemset/problem/1739/B 2 3 B. Array Recovery 4 5 time limit per test 6 7 2 seconds 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 For an array of non-negative integers $a$ of size $n$, we construct another array $d$ as follows: $d_1 = a_1$, $d_i = |a_i - a_{i - 1}|$ for $2 \le i \le n$. 22 23 Your task is to restore the array $a$ from a given array $d$, or to report that there are multiple possible arrays. 24 25 Input 26 27 The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. 28 29 The first line of each test case contains one integer $n$ ($1 \le n \le 100$) — the size of the arrays $a$ and $d$. 30 31 The second line contains $n$ integers $d_1, d_2, \dots, d_n$ ($0 \le d_i \le 100$) — the elements of the array $d$. 32 33 It can be shown that there always exists at least one suitable array $a$ under these constraints. 34 35 Output 36 37 For each test case, print the elements of the array $a$, if there is only one possible array $a$. Otherwise, print $-1$. 38 39 Example 40 41 Input 42 43 ``` 44 3 45 46 4 47 48 1 0 2 5 49 50 3 51 52 2 6 3 53 54 5 55 56 0 0 0 0 0 57 ``` 58 59 Output 60 61 ``` 62 1 1 3 8 63 -1 64 0 0 0 0 0 65 ``` 66 67 Note 68 69 In the second example, there are two suitable arrays: $[2, 8, 5]$ and $[2, 8, 11]$.