#K42222. Non-decreasing Subsequence Contest Participation
Non-decreasing Subsequence Contest Participation
Non-decreasing Subsequence Contest Participation
You are given several test cases. In each test case, you are provided with a sequence of ingredient quality values. Your task is to determine if there exists a non-decreasing subsequence within the sequence that has a length of at least K. Formally, for each test case, given an array A of length N and an integer K, check whether there is a subsequence (not necessarily contiguous) A[i1], A[i2], ... , A[im] (with m \geq K and i1 < i2 < ... < im) such that:
$$A[i_1] \leq A[i_2] \leq \cdots \leq A[i_m]$$
If such a subsequence exists, print YES
; otherwise, print NO
for that test case.
inputFormat
The input is read from stdin
and has the following format:
T N A[0] A[1] ... A[N-1] K ... (repeated for T test cases)
Where:
T
is the number of test cases.- For each test case,
N
is the number of ingredients. - The next line contains
N
space-separated integers representing the quality values of the ingredients. K
is the minimum required length of the non-decreasing subsequence.
outputFormat
For each test case, output a single line to stdout
containing either YES
if there exists a non-decreasing subsequence of length at least K, or NO
if there is not.
2
5
1 3 2 4 5
3
4
4 3 2 1
2
YES
NO
</p>