2065C1.md (2195B)
1 Source: https://codeforces.com/problemset/problem/2065/C1 2 3 C1. Skibidus and Fanum Tax (easy version) 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 This is the easy version of the problem. In this version, $m = 1$. 22 23 Skibidus has obtained two arrays $a$ and $b$, containing $n$ and $m$ elements respectively. For each integer $i$ from $1$ to $n$, he is allowed to perform the operation at most once: 24 25 * Choose an integer $j$ such that $1 \leq j \leq m$. Set $a_i := b_j - a_i$. Note that $a_i$ may become non-positive as a result of this operation. 26 27 Skibidus needs your help determining whether he can sort $a$ in non-decreasing order$^{\text{∗}}$ by performing the above operation some number of times. 28 29 $^{\text{∗}}$$a$ is sorted in non-decreasing order if $a_1 \leq a_2 \leq \ldots \leq a_n$. 30 31 Input 32 33 The first line contains an integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. 34 35 The first line of each test case contains two integers $n$ and $m$ ($1 \leq n \leq 2 \cdot 10^5$, $\textbf{m = 1}$). 36 37 The following line of each test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$). 38 39 The following line of each test case contains $m$ integers $b_1, b_2, \ldots, b_m$ ($1 \leq b_i \leq 10^9$). 40 41 It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases does not exceed $2 \cdot 10^5$. 42 43 Output 44 45 For each test case, if it is possible to sort $a$ in non-decreasing order, print "YES" on a new line. Otherwise, print "NO" on a new line. 46 47 You can output the answer in any case. For example, the strings "yEs", "yes", and "Yes" will also be recognized as positive responses. 48 49 Example 50 51 Input 52 53 ``` 54 5 55 56 1 1 57 58 5 59 60 9 61 62 3 1 63 64 1 4 3 65 66 3 67 68 4 1 69 70 1 4 2 5 71 72 6 73 74 4 1 75 76 5 4 10 5 77 78 4 79 80 3 1 81 82 9 8 7 83 84 8 85 ``` 86 87 Output 88 89 ``` 90 YES 91 NO 92 YES 93 NO 94 YES 95 ``` 96 97 Note 98 99 In the first test case, $[5]$ is already sorted. 100 101 In the second test case, it can be shown that it is impossible. 102 103 In the third test case, we can set $a_3:=b_1-a_3=6-2=4$. The sequence $[1,4,4,5]$ is in nondecreasing order. 104 105 In the last case, we can apply operations on each index. The sequence becomes $[-1,0,1]$, which is in nondecreasing order.