309810: CF1739B. Array Recovery

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Array Recovery

题意翻译

有一个非负整数序列 $a$,定义 $d_1=a_1,d_i=|a_i-a_{i-1}|$。 现在给出序列 $d$,问是否能确定唯一的序列 $a$。不能输出 $-1$,否则输出序列 $a$。

题目描述

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 $ . Your task is to restore the array $ a $ from a given array $ d $ , or to report that there are multiple possible arrays.

输入输出格式

输入格式


The first line contains a single integer $ t $ ( $ 1 \le t \le 100 $ ) — the number of test cases. The first line of each test case contains one integer $ n $ ( $ 1 \le n \le 100 $ ) — the size of the arrays $ a $ and $ d $ . 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 $ . It can be shown that there always exists at least one suitable array $ a $ under these constraints.

输出格式


For each test case, print the elements of the array $ a $ , if there is only one possible array $ a $ . Otherwise, print $ -1 $ .

输入输出样例

输入样例 #1

3
4
1 0 2 5
3
2 6 3
5
0 0 0 0 0

输出样例 #1

1 1 3 8
-1
0 0 0 0 0

说明

In the second example, there are two suitable arrays: $ [2, 8, 5] $ and $ [2, 8, 11] $ .

Input

题意翻译

有一个非负整数序列 $a$,定义 $d_1=a_1,d_i=|a_i-a_{i-1}|$。 现在给出序列 $d$,问是否能确定唯一的序列 $a$。不能输出 $-1$,否则输出序列 $a$。

Output

题目大意:
给定一个非负整数序列 \(a\),定义另一个序列 \(d\),其中 \(d_1 = a_1\),对于 \(2 \le i \le n\),有 \(d_i = |a_i - a_{i-1}|\)。现在给出序列 \(d\),需要判断是否能唯一确定序列 \(a\)。如果能,输出序列 \(a\);如果不能,输出 \(-1\)。

输入输出数据格式:
- 输入格式:
- 第一行包含一个整数 \(t\)(\(1 \le t \le 100\)),表示测试用例的数量。
- 每个测试用例的第一行包含一个整数 \(n\)(\(1 \le n \le 100\)),表示数组 \(a\) 和 \(d\) 的长度。
- 每个测试用例的第二行包含 \(n\) 个整数 \(d_1, d_2, \dots, d_n\)(\(0 \le d_i \le 100\)),表示数组 \(d\) 的元素。
- 输出格式:
- 对于每个测试用例,如果存在唯一的序列 \(a\),则输出该序列的元素;否则,输出 \(-1\)。

输入输出样例:
- 输入样例 #1:
```
3
4
1 0 2 5
3
2 6 3
5
0 0 0 0 0
```
- 输出样例 #1:
```
1 1 3 8
-1
0 0 0 0 0
```题目大意: 给定一个非负整数序列 \(a\),定义另一个序列 \(d\),其中 \(d_1 = a_1\),对于 \(2 \le i \le n\),有 \(d_i = |a_i - a_{i-1}|\)。现在给出序列 \(d\),需要判断是否能唯一确定序列 \(a\)。如果能,输出序列 \(a\);如果不能,输出 \(-1\)。 输入输出数据格式: - 输入格式: - 第一行包含一个整数 \(t\)(\(1 \le t \le 100\)),表示测试用例的数量。 - 每个测试用例的第一行包含一个整数 \(n\)(\(1 \le n \le 100\)),表示数组 \(a\) 和 \(d\) 的长度。 - 每个测试用例的第二行包含 \(n\) 个整数 \(d_1, d_2, \dots, d_n\)(\(0 \le d_i \le 100\)),表示数组 \(d\) 的元素。 - 输出格式: - 对于每个测试用例,如果存在唯一的序列 \(a\),则输出该序列的元素;否则,输出 \(-1\)。 输入输出样例: - 输入样例 #1: ``` 3 4 1 0 2 5 3 2 6 3 5 0 0 0 0 0 ``` - 输出样例 #1: ``` 1 1 3 8 -1 0 0 0 0 0 ```

加入题单

算法标签: