[Solution] Directional Increase Codeforces Solution | Codeforces Problem Solution 2022
We have an array of length . Initially, each element is equal to 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 . 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 . 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 . Determine whether it's possible to obtain after some operations or not.
The first line contains a single integer — the number of test cases. The description of the test cases follows.
The first line of each test case contains a single integer — the size of array .
The second line of each test case contains integers () — elements of the array.
It is guaranteed that the sum of over all test cases doesn't exceed .
For each test case, print "Yes" (without quotes) if it's possible to obtain 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).
No comments:
Post a Comment