codeforces-scrape

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

1291B.md (2384B)


      1 Source: https://codeforces.com/problemset/problem/1291/B
      2 
      3 B. Array Sharpening
      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 You're given an array $a_1, \ldots, a_n$ of $n$ non-negative integers.
     22 
     23 Let's call it sharpened if and only if there exists an integer $1 \le k \le n$ such that $a_1 \lt a_2 \lt \ldots \lt a_k$ and $a_k \gt a_{k+1} \gt \ldots \gt a_n$. In particular, any strictly increasing or strictly decreasing array is sharpened. For example:
     24 
     25 * The arrays $[4]$, $[0, 1]$, $[12, 10, 8]$ and $[3, 11, 15, 9, 7, 4]$ are sharpened;
     26 * The arrays $[2, 8, 2, 8, 6, 5]$, $[0, 1, 1, 0]$ and $[2, 5, 6, 9, 8, 8]$ are not sharpened.
     27 
     28 You can do the following operation as many times as you want: choose any strictly positive element of the array, and decrease it by one. Formally, you can choose any $i$ ($1 \le i \le n$) such that $a_i \gt 0$ and assign $a_i := a_i - 1$.
     29 
     30 Tell if it's possible to make the given array sharpened using some number (possibly zero) of these operations.
     31 
     32 Input
     33 
     34 The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 15\ 000$)  — 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 3 \cdot 10^5$).
     37 
     38 The second line of each test case contains a sequence of $n$ non-negative integers $a_1, \ldots, a_n$ ($0 \le a_i \le 10^9$).
     39 
     40 It is guaranteed that the sum of $n$ over all test cases does not exceed $3 \cdot 10^5$.
     41 
     42 Output
     43 
     44 For each test case, output a single line containing "Yes" (without quotes) if it's possible to make the given array sharpened using the described operations, or "No" (without quotes) otherwise.
     45 
     46 Example
     47 
     48 Input
     49 
     50 ```
     51 10
     52 1
     53 248618
     54 3
     55 12 10 8
     56 6
     57 100 11 15 9 7 8
     58 4
     59 0 1 1 0
     60 2
     61 0 0
     62 2
     63 0 1
     64 2
     65 1 0
     66 2
     67 1 1
     68 3
     69 0 1 0
     70 3
     71 1 0 1
     72 ```
     73 
     74 Output
     75 
     76 ```
     77 Yes
     78 Yes
     79 Yes
     80 No
     81 No
     82 Yes
     83 Yes
     84 Yes
     85 Yes
     86 No
     87 ```
     88 
     89 Note
     90 
     91 In the first and the second test case of the first test, the given array is already sharpened.
     92 
     93 In the third test case of the first test, we can transform the array into $[3, 11, 15, 9, 7, 4]$ (decrease the first element $97$ times and decrease the last element $4$ times). It is sharpened because $3 \lt 11 \lt 15$ and $15 \gt 9 \gt 7 \gt 4$.
     94 
     95 In the fourth test case of the first test, it's impossible to make the given array sharpened.