#C11775. Non-Decreasing Flower Height Subsequence

    ID: 41128 Type: Default 1000ms 256MiB

Non-Decreasing Flower Height Subsequence

Non-Decreasing Flower Height Subsequence

Given a sequence of flower heights, determine if it is possible to select a subsequence (of at least two flowers) that is non-decreasing. In other words, check if there exists a pair of flowers in the sequence that can be chosen (not necessarily adjacent in the original list) such that the later flower's height is not lower than the earlier one.

You are given \(T\) test cases. For each test case, the first input is an integer \(n\) representing the number of flowers, followed by \(n\) integers representing the heights of the flowers. If there exists a non-decreasing subsequence of length at least two, print YES; otherwise, print NO.

Note: A valid subsequence must contain at least two elements. A single flower does not count as a valid subsequence.

inputFormat

The input is received from stdin and has the following format:

T
n
h1 h2 ... hn
...

Where:

  • T is the number of test cases.
  • For each test case, the first line contains an integer n (the number of flowers).
  • The second line contains n space-separated integers representing the flower heights.

outputFormat

For each test case, output a single line to stdout containing YES if it is possible to form a non-decreasing subsequence of at least two flowers, or NO otherwise.

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

NO YES YES NO

</p>