CF1713B.Optimal Reduction

传统题 时间 2000 ms 内存 256 MiB 5 尝试 1 已通过 1 标签

Optimal Reduction

Consider an array aa of nn positive integers.

You may perform the following operation:

  • select two indices ll and rr (1≤l≤r≤n1 \leq l \leq r \leq n), then
  • decrease all elements al,al+1,…,ara_l, a_{l + 1}, \dots, a_r by 11.

Let's call f(a)f(a) the minimum number of operations needed to change array aa into an array of nn zeros.

Determine if for all permutations†^\dagger bb of aa, f(a)≤f(b)f(a) \leq f(b) is true.

†^\dagger An array bb is a permutation of an array aa if bb consists of the elements of aa in arbitrary order. For example, [4,2,3,4][4,2,3,4] is a permutation of [3,2,4,4][3,2,4,4] while [1,2,2][1,2,2] is not a permutation of [1,2,3][1,2,3].

Input

The first line contains a single integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains a single integer nn (1≤n≤1051 \leq n \leq 10^5) — the length of the array aa.

The second line contains nn integers a1,a2,…,ana_1, a_2, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9) — description of the array aa.

It is guaranteed that the sum of nn over all test cases does not exceed 10510^5.

Output

For each test case, print "YES" (without quotes) if for all permutations bb of aa, f(a)≤f(b)f(a) \leq f(b) is true, and "NO" (without quotes) otherwise.

You can output "YES" and "NO" in any case (for example, strings "yEs", "yes" and "Yes" will be recognized as a positive response).

Note

In the first test case, we can change all elements to 00 in 55 operations. It can be shown that no permutation of [2,3,5,4][2, 3, 5, 4] requires less than 55 operations to change all elements to 00.

In the third test case, we need 55 operations to change all elements to 00, while [2,3,3,1][2, 3, 3, 1] only needs 33 operations.

Samples

3
4
2 3 5 4
3
1 2 3
4
3 1 3 2
YES
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验