CF1713B.Optimal Reduction

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Consider an array aa of nn positive integers.

You may perform the following operation:

  • select two indices ll and rr ( 1lrn1 \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] .

输入格式

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

The first line of each test case contains a single integer nn ( 1n1051 \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 ( 1ai1091 \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 .

输出格式

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).

输入输出样例

  • 输入#1

    3
    4
    2 3 5 4
    3
    1 2 3
    4
    3 1 3 2

    输出#1

    YES
    YES
    NO

说明/提示

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.

首页