CF1693A.Directional Increase
普及/提高-
通过率:0%
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
We have an array of length n . Initially, each element is equal to 0 and there is a pointer located on the first element.
We can do the following two kinds of operations any number of times (possibly zero) in any order:
- If the pointer is not on the last element, increase the element the pointer is currently on by 1 . Then move it to the next element.
- If the pointer is not on the first element, decrease the element the pointer is currently on by 1 . Then move it to the previous element.
But there is one additional rule. After we are done, the pointer has to be on the first element.
You are given an array a . Determine whether it's possible to obtain a after some operations or not.
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer n (1≤n≤2⋅105) — the size of array a .
The second line of each test case contains n integers a1,a2,…,an ( −109≤ai≤109 ) — elements of the array.
It is guaranteed that the sum of n over all test cases doesn't exceed 2⋅105 .
输出格式
For each test case, print "Yes" (without quotes) if it's possible to obtain a after some operations, and "No" (without quotes) otherwise.
You can output "Yes" and "No" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).
输入输出样例
输入#1
7 2 1 0 4 2 -1 -1 0 4 1 -4 3 0 4 1 -1 1 -1 5 1 2 3 4 -10 7 2 -1 1 -2 0 0 0 1 0
输出#1
No Yes No No Yes Yes Yes
说明/提示
In the first test case we can obtain the array after some operations, but the pointer won't be on the first element.
One way of obtaining the array in the second test case is shown below.
⟨0,0,0,0⟩→⟨1,0,0,0⟩→⟨1,−1,0,0⟩→⟨2,−1,0,0⟩→⟨2,0,0,0⟩→⟨2,0,−1,0⟩→⟨2,−1,−1,0⟩