#C7722. Candy Sorting Problem

    ID: 51625 Type: Default 1000ms 256MiB

Candy Sorting Problem

Candy Sorting Problem

You are given a collection of candies represented as a sequence of integers. The candies are arranged in some order, and your task is to determine whether the sequence can be arranged in non-decreasing order using at most one operation. In other words, you are allowed to have at most one instance where an element is greater than its following element. Mathematically, a sorted (non-decreasing) sequence satisfies the condition \[ a_1 \le a_2 \le \dots \le a_n \] for an array \(a = [a_1, a_2, \dots, a_n]\).

If the given sequence is already sorted or there exists exactly one pair of adjacent elements where \(a_i > a_{i+1}\), then the answer is YES; otherwise, the answer is NO.

The input consists of multiple test cases. For each test case, you should output the result on a new line.

inputFormat

The first line of the input contains an integer \(T\) denoting the number of test cases. The description of each test case is as follows:

  • The first line contains a single integer \(n\) — the number of candies.
  • The second line contains \(n\) integers representing the candy collection.

All input is provided via standard input (stdin).

outputFormat

For each test case, output a single line containing either YES if the candy collection can be sorted using at most one operation, or NO otherwise. The output should be printed to standard output (stdout).

## sample
3
4
3 1 2 4
5
1 2 3 4 5
3
3 2 1
YES

YES NO

</p>