CF1739B.Array Recovery

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

For an array of non-negative integers aa of size nn, we construct another array dd as follows: d1=a1d_1 = a_1, di=∣ai−ai−1∣d_i = |a_i - a_{i - 1}| for 2≤i≤n2 \le i \le n.

Your task is to restore the array aa from a given array dd, or to report that there are multiple possible arrays.

对于一个长度为 nn 的非负整数数组 aa,我们按如下方式构造另一个数组 dd:d1=a1d_1 = a_1,且对 2≤i≤n2 \le i \le n,有 di=∣ai−ai−1∣d_i = |a_i - a_{i - 1}|。

你的任务是根据给定的数组 dd 还原出数组 aa,或者判断存在多个可能的数组。

输入格式

The first line contains a single integer tt (1≤t≤1001 \le t \le 100) — the number of test cases.

The first line of each test case contains one integer nn (1≤n≤1001 \le n \le 100) — the size of the arrays aa and dd.

The second line contains nn integers d1,d2,…,dnd_1, d_2, \dots, d_n (0≤di≤1000 \le d_i \le 100) — the elements of the array dd.

It can be shown that there always exists at least one suitable array aa under these constraints.

第一行包含一个整数 tt(1≤t≤1001 \le t \le 100)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1001 \le n \le 100)—— 数组 aa 和 dd 的大小。

每个测试用例的第二行包含 nn 个整数 d1,d2,…,dnd_1, d_2, \dots, d_n(0≤di≤1000 \le d_i \le 100)—— 数组 dd 的元素。

在这些约束条件下,可以证明至少存在一个满足要求的数组 aa。

输出格式

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

对于每个测试用例,如果仅存在一个可能的数组 aa,则输出数组 aa 的所有元素;否则输出 −1-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][2, 8, 5] and [2,8,11][2, 8, 11].

在第二个例子中,有两个合适的数组:[2,8,5][2, 8, 5] 和 [2,8,11][2, 8, 11]。

输入解题思路,AI测评打分。不知道怎么写?

首页