GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Monday, 8 August 2022

[Solution] Optimal Reduction Codeforces Solution




B. Optimal Reduction
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

Consider an array a of n positive integers.

You may perform the following operation:

  • select two indices l and r (1lrn), 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 af(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

Solution Click Below:-  👉CLICK HERE👈

👇👇👇👇👇

 occupied

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

Input

The first line contains a single integer t (1t104) — the number of test cases.

The first line of each test case contains a single integer n (1n105) — the length of the array a.

The second line contains n integers a1,a2,,an (1ai109) — description of the array a.

It is guaranteed that the sum of n over all test cases does not exceed 105.

Output

For each test case, print "YES" (without quotes) if for all permutations b of af(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).

No comments:

Post a Comment