CF1713B.Optimal Reduction
入门
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Consider an array a of n positive integers.
You may perform the following operation:
- select two indices l and r (1≤l≤r≤n), then
- decrease all elements al,al+1,…,ar by 1.
Let's call f(a) the minimum number of operations needed to change array a into an array of n zeros.
Determine if for all permutations† b of a, f(a)≤f(b) is true.
† An array b is a permutation of an array a if b consists of the elements of a in arbitrary order. For example, [4,2,3,4] is a permutation of [3,2,4,4] while [1,2,2] is not a permutation of [1,2,3].
考虑一个包含 n 个正整数的数组 a。
你可以执行以下操作:
- 选择两个下标 l 和 r(满足 1≤l≤r≤n),然后
- 将所有元素 al,al+1,…,ar 同时减 1。
定义 f(a) 为将数组 a 变为全零数组所需的最少操作次数。
判断是否对 a 的所有排列† b,均有 f(a)≤f(b) 成立。
† 若数组 b 由数组 a 的元素以任意顺序组成,则称 b 是 a 的一个排列。例如,[4,2,3,4] 是 [3,2,4,4] 的一个排列,而 [1,2,2] 不是 [1,2,3] 的排列。
输入格式
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains a single integer n (1≤n≤105) — the length of the array a.
The second line contains n integers a1,a2,…,an (1≤ai≤109) — description of the array a.
It is guaranteed that the sum of n over all test cases does not exceed 105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含一个整数 n(1≤n≤105)—— 数组 a 的长度。
第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 数组 a 的描述。
保证所有测试用例的 n 之和不超过 105。
输出格式
For each test case, print "YES" (without quotes) if for all permutations b of a, f(a)≤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).
对于每个测试用例,如果对数组 a 的所有排列 b 均满足 f(a)≤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 0 in 5 operations. It can be shown that no permutation of [2,3,5,4] requires less than 5 operations to change all elements to 0.
In the third test case, we need 5 operations to change all elements to 0, while [2,3,3,1] only needs 3 operations.
在第一个测试用例中,我们可以在 5 次操作内将所有元素变为 0。可以证明:对于排列 [2,3,5,4] 的任意排列,将其所有元素变为 0 所需的操作次数均不少于 5。
在第三个测试用例中,我们需要 5 次操作将所有元素变为 0,而 [2,3,3,1] 仅需 3 次操作。
输入解题思路,AI测评打分。不知道怎么写?