codeforces-scrape

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

1851D.md (2262B)


      1 Source: https://codeforces.com/problemset/problem/1851/D
      2 
      3 D. Prefix Permutation Sums
      4 
      5 time limit per test
      6 
      7 3 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 Your friends have an array of $n$ elements, calculated its array of prefix sums and passed it to you, accidentally losing one element during the transfer. Your task is to find out if the given array can matches permutation.
     22 
     23 A permutation of $n$ elements is an array of $n$ numbers from $1$ to $n$ such that each number occurs exactly one times in it.
     24 
     25 The array of prefix sums of the array $a$ — is such an array $b$ that $b_i = \sum_{j=1}^i a_j, 1 \le i \le n$.
     26 
     27 For example, the original permutation was $[1, 5, 2, 4, 3]$. Its array of prefix sums — $[1, 6, 8, 12, 15]$. Having lost one element, you can get, for example, arrays $[6, 8, 12, 15]$ or $[1, 6, 8, 15]$.
     28 
     29 It can also be shown that the array $[1, 2, 100]$ does not correspond to any permutation.
     30 
     31 Input
     32 
     33 The first line contains a positive number $t$ ($1 \le t \le 10^4$) — the number of test cases. The description of the test cases follows.
     34 
     35 The first line of the description of each test case contains a positive number $n$ ($2 \le n \le 2 \cdot 10^5$) — the size of the initial array.
     36 
     37 The second line of the description of each test case contains $n - 1$ positive number $a_i$ ($1 \le a_i \le 10^{18}$), $a_{i-1} \lt a_i$ — elements of the array of prefix sums.
     38 
     39 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
     40 
     41 Output
     42 
     43 For each test case, output "YES" if such a permutation exists, and "NO" otherwise.
     44 
     45 You can output "YES" and "NO" in any case (for example, the strings "yEs", "yes" and "Yes" will be recognized as a positive response).
     46 
     47 Example
     48 
     49 Input
     50 
     51 ```
     52 12
     53 
     54 5
     55 
     56 6 8 12 15
     57 
     58 5
     59 
     60 1 6 8 15
     61 
     62 4
     63 
     64 1 2 100
     65 
     66 4
     67 
     68 1 3 6
     69 
     70 2
     71 
     72 2
     73 
     74 3
     75 
     76 1 2
     77 
     78 4
     79 
     80 3 7 10
     81 
     82 5
     83 
     84 5 44 46 50
     85 
     86 4
     87 
     88 1 9 10
     89 
     90 5
     91 
     92 13 21 36 42
     93 
     94 5
     95 
     96 1 2 3 1000000000000000000
     97 
     98 9
     99 
    100 9 11 12 20 25 28 30 33
    101 ```
    102 
    103 Output
    104 
    105 ```
    106 YES
    107 YES
    108 NO
    109 YES
    110 YES
    111 NO
    112 YES
    113 NO
    114 NO
    115 NO
    116 NO
    117 NO
    118 ```
    119 
    120 Note
    121 
    122 In the fourth example, for example, the permutation $[1, 2, 3, 4]$ is suitable. In the fifth example, for example, the permutation $[2, 1]$ is suitable. In the seventh example, for example, the permutation $[1, 2, 4, 3]$ is suitable.