codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1941B.md (1991B)


      1 Source: https://codeforces.com/problemset/problem/1941/B
      2 
      3 B. Rudolf and 121
      4 
      5 time limit per test
      6 
      7 2 seconds
      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 Rudolf has an array $a$ of $n$ integers, the elements are numbered from $1$ to $n$.
     22 
     23 In one operation, he can choose an index $i$ ($2 \le i \le n - 1$) and assign:
     24 
     25 * $a_{i - 1} = a_{i - 1} - 1$
     26 * $a_i = a_i - 2$
     27 * $a_{i + 1} = a_{i + 1} - 1$
     28 
     29 Rudolf can apply this operation any number of times. Any index $i$ can be used zero or more times.
     30 
     31 Can he make all the elements of the array equal to zero using this operation?
     32 
     33 Input
     34 
     35 The first line of the input contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test.
     36 
     37 The first line of each case contains a single integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of elements in the array.
     38 
     39 The second line of each case contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_j \le 10^9$) — the elements of the array.
     40 
     41 It is guaranteed that the sum of the values of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     42 
     43 Output
     44 
     45 For each test case, output "YES" if it is possible to make all the elements of the array zero using the described operations. Otherwise, output "NO".
     46 
     47 You can output each letter in any case (lowercase or uppercase). For example, the strings "yEs", "yes", "Yes", and "YES" will be accepted as a positive answer.
     48 
     49 Example
     50 
     51 Input
     52 
     53 ```
     54 7
     55 
     56 5
     57 
     58 1 3 5 5 2
     59 
     60 5
     61 
     62 2 4 4 5 1
     63 
     64 5
     65 
     66 0 1 3 3 1
     67 
     68 6
     69 
     70 5 6 0 2 3 0
     71 
     72 4
     73 
     74 1 2 7 2
     75 
     76 3
     77 
     78 7 1 0
     79 
     80 4
     81 
     82 1 1 1 1
     83 ```
     84 
     85 Output
     86 
     87 ```
     88 YES
     89 NO
     90 YES
     91 NO
     92 NO
     93 NO
     94 NO
     95 ```
     96 
     97 Note
     98 
     99 In the first example, the original array is $[1, 3, 5, 5, 2]$, to make all its elements zero, Rudolf can act as follows:
    100 
    101 * apply the operation at $i=4$ and get the array $[1, 3, 4, 3, 1]$;
    102 * apply the operation at $i=3$ and get the array $[1, 2, 2, 2, 1]$;
    103 * apply the operation at $i=2$ and get the array $[0, 0, 1, 2, 1]$;
    104 * apply the operation at $i=4$ and get the array $[0, 0, 0, 0, 0]$.