1717C.md (2147B)
1 Source: https://codeforces.com/problemset/problem/1717/C 2 3 C. Madoka and Formal Statement 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 Given an array of integer $a_1, a_2, \ldots, a_n$. In one operation you can make $a_i := a_i + 1$ if $i \lt n$ and $a_i \leq a_{i + 1}$, or $i = n$ and $a_i \leq a_1$. 22 23 You need to check whether the array $a_1, a_2, \ldots, a_n$ can become equal to the array $b_1, b_2, \ldots, b_n$ in some number of operations (possibly, zero). Two arrays $a$ and $b$ of length $n$ are called equal if $a_i = b_i$ for all integers $i$ from $1$ to $n$. 24 25 Input 26 27 The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 4 \cdot 10^4$) — the number of test cases. Description of the test cases follows. 28 29 The first line of each test case contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) – the length of the array. 30 31 The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10^9$) – the elements of the array $a$. 32 33 The third line of each test case contains $n$ integers $b_1, \ldots, b_n$ ($1 \le b_i \le 10^9$) – the elements of the array $b$. 34 35 It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. 36 37 Output 38 39 For each test case, output "YES" if you can get the array $b$, otherwise output "NO". 40 41 You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer). 42 43 Example 44 45 Input 46 47 ``` 48 5 49 50 3 51 52 1 2 5 53 54 1 2 5 55 56 2 57 58 2 2 59 60 1 3 61 62 4 63 64 3 4 1 2 65 66 6 4 2 5 67 68 3 69 70 2 4 1 71 72 4 5 3 73 74 5 75 76 1 2 3 4 5 77 78 6 5 6 7 6 79 ``` 80 81 Output 82 83 ``` 84 YES 85 NO 86 NO 87 NO 88 YES 89 ``` 90 91 Note 92 93 In the first test case, the array $a$ is already equal to the array $b$. 94 95 In the second test case, we can't get the array $b$, because to do this we need to decrease $a_1$. 96 97 In the fifth test case, we can apply operations in order to the elements with indices $4, 3, 3,2,2,2,1,1,1,1$, and then get the array $[5,5,5,5,5]$. After that, you can apply operations in order to elements with indices $5,4,4,3,1$ and already get an array $[6,5,6,7,6]$.