Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Suppose we have a sequence of non-negative integers, Namely a1, a2, ..., an. At each time we can choose one term ai
- with 0 < i < n and we subtract 1 from both ai and ai+1. We wonder whether we can get a sequence of all zeros after
- several operations.
- Input
- The first line is the number of test cases T (0 < T <= 20).
- The first line of each test case is a number N (0 < N <= 10000). The next line is N non-negative integers, 0 <= ai <= 109.
- Output
- If it can be modified into all zeros with several operations output “YES” in a single line, otherwise output “NO” instead.
- Example
- Input:
- 2
- 2
- 1 2
- 2
- 2 2
- Output:
- NO
- YES
- Explanation
- It is clear that [1 2] can be reduced to [0 1] but no further to convert all integers to 0. Hence, the output is NO.
- In second case, output is YES as [2 2] can be reduced to [1 1] and then to [0 0] in just two steps.
- */
- #include <stdio.h>
- int NITK06(long long a[], int size)
- {
- int n = 0;
- while (n < size-1) {
- a[n+1] -= a[n];
- a[n] = 0;
- n += 1;
- }
- if(a[size-1] != 0)
- return 0;
- return 1;
- }
- int main(void) {
- // your code here
- int t,size;
- long long a[100000];
- scanf("%d",&t);
- while(t--)
- {
- scanf("%d",&size);
- for(int i=0;i<size;i++)
- scanf("%lld",&a[i]);
- if(NITK06(a, size))
- printf("YES\n");
- else
- printf("NO\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment