1693A.md (2321B)
1 Source: https://codeforces.com/problemset/problem/1693/A 2 3 A. Directional Increase 4 5 time limit per test 6 7 1 second 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 We have an array of length $n$. Initially, each element is equal to $0$ and there is a pointer located on the first element. 22 23 We can do the following two kinds of operations any number of times (possibly zero) in any order: 24 25 1. 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. 26 2. 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. 27 28 But there is one additional rule. After we are done, the pointer has to be on the first element. 29 30 You are given an array $a$. Determine whether it's possible to obtain $a$ after some operations or not. 31 32 Input 33 34 The first line contains a single integer $t$ $(1\le t\le 1000)$ — the number of test cases. The description of the test cases follows. 35 36 The first line of each test case contains a single integer $n$ $(1\le n\le 2 \cdot 10^5)$ — the size of array $a$. 37 38 The second line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^9 \le a_i \le 10^9$) — elements of the array. 39 40 It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2 \cdot 10^5$. 41 42 Output 43 44 For each test case, print "Yes" (without quotes) if it's possible to obtain $a$ after some operations, and "No" (without quotes) otherwise. 45 46 You can output "Yes" and "No" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response). 47 48 Example 49 50 Input 51 52 ``` 53 7 54 2 55 1 0 56 4 57 2 -1 -1 0 58 4 59 1 -4 3 0 60 4 61 1 -1 1 -1 62 5 63 1 2 3 4 -10 64 7 65 2 -1 1 -2 0 0 0 66 1 67 0 68 ``` 69 70 Output 71 72 ``` 73 No 74 Yes 75 No 76 No 77 Yes 78 Yes 79 Yes 80 ``` 81 82 Note 83 84 In the first test case we can obtain the array after some operations, but the pointer won't be on the first element. 85 86 One way of obtaining the array in the second test case is shown below. 87 88 $\langle \underline{0}, 0, 0, 0\rangle \to \langle 1, \underline{0}, 0, 0 \rangle \to \langle \underline{1}, -1, 0, 0\rangle \to \langle 2, \underline{-1}, 0, 0\rangle \to \langle 2, 0, \underline{0}, 0\rangle \to \langle 2, \underline{0}, -1, 0\rangle \to \langle \underline{2}, -1, -1, 0\rangle$