CF1739B.Array Recovery
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
For an array of non-negative integers a of size n, we construct another array d as follows: d1=a1, di=∣ai−ai−1∣ for 2≤i≤n.
Your task is to restore the array a from a given array d, or to report that there are multiple possible arrays.
对于一个长度为 n 的非负整数数组 a,我们按如下方式构造另一个数组 d:d1=a1,且对 2≤i≤n,有 di=∣ai−ai−1∣。
你的任务是根据给定的数组 d 还原出数组 a,或者判断存在多个可能的数组。
输入格式
The first line contains a single integer t (1≤t≤100) — the number of test cases.
The first line of each test case contains one integer n (1≤n≤100) — the size of the arrays a and d.
The second line contains n integers d1,d2,…,dn (0≤di≤100) — the elements of the array d.
It can be shown that there always exists at least one suitable array a under these constraints.
第一行包含一个整数 t(1≤t≤100)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤100)—— 数组 a 和 d 的大小。
每个测试用例的第二行包含 n 个整数 d1,d2,…,dn(0≤di≤100)—— 数组 d 的元素。
在这些约束条件下,可以证明至少存在一个满足要求的数组 a。
输出格式
For each test case, print the elements of the array a, if there is only one possible array a. Otherwise, print −1.
对于每个测试用例,如果仅存在一个可能的数组 a,则输出数组 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
说明/提示
In the second example, there are two suitable arrays: [2,8,5] and [2,8,11].
在第二个例子中,有两个合适的数组:[2,8,5] 和 [2,8,11]。
输入解题思路,AI测评打分。不知道怎么写?