CF1713B.Optimal Reduction

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

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

考虑一个包含 nn 个正整数的数组 aa。

你可以执行以下操作:

  • 选择两个下标 ll 和 rr(满足 1≤l≤r≤n1 \leq l \leq r \leq n),然后
  • 将所有元素 al,al+1,…,ara_l, a_{l + 1}, \dots, a_r 同时减 11。

定义 f(a)f(a) 为将数组 aa 变为全零数组所需的最少操作次数。

判断是否对 aa 的所有排列†^\dagger bb,均有 f(a)≤f(b)f(a) \leq f(b) 成立。

†^\dagger 若数组 bb 由数组 aa 的元素以任意顺序组成,则称 bb 是 aa 的一个排列。例如,[4,2,3,4][4,2,3,4] 是 [3,2,4,4][3,2,4,4] 的一个排列,而 [1,2,2][1,2,2] 不是 [1,2,3][1,2,3] 的排列。

输入格式

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.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含一个整数 nn(1≤n≤1051 \leq n \leq 10^5)—— 数组 aa 的长度。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \dots, a_n(1≤ai≤1091 \le a_i \le 10^9)—— 数组 aa 的描述。

保证所有测试用例的 nn 之和不超过 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).

对于每个测试用例,如果对数组 aa 的所有排列 bb 均满足 f(a)≤f(b)f(a) \leq f(b),则输出 "YES"(不带引号);否则输出 "NO"(不带引号)。

你可以以任意大小写形式输出 "YES" 和 "NO"(例如,字符串 "yEs"、"yes" 和 "Yes" 均会被识别为肯定回答)。

输入输出样例

  • 输入#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.

在第一个测试用例中,我们可以在 55 次操作内将所有元素变为 00。可以证明:对于排列 [2,3,5,4][2, 3, 5, 4] 的任意排列,将其所有元素变为 00 所需的操作次数均不少于 55。

在第三个测试用例中,我们需要 55 次操作将所有元素变为 00,而 [2,3,3,1][2, 3, 3, 1] 仅需 33 次操作。

输入解题思路,AI测评打分。不知道怎么写?

首页