#C11262. Forming a Non-Decreasing Subsequence
Forming a Non-Decreasing Subsequence
Forming a Non-Decreasing Subsequence
You are given a list of n integers and an integer k. Your task is to determine whether it is possible to select exactly k integers from the list such that, after reordering them in non-decreasing order, the sequence is valid.
In other words, you need to check if k ≤ n. If it is, then you can always form a non-decreasing sequence by sorting the selected numbers.
The answer should be output as YES
if it is possible and NO
otherwise.
Mathematically, the condition can be expressed as:
[ \text{Answer} = \begin{cases} YES, & \text{if } k \le n, \ NO, & \text{if } k > n. \end{cases} ]
inputFormat
The first line contains two integers n and k separated by a space.
The second line contains n integers separated by spaces representing the list.
outputFormat
Output a single line containing either YES
or NO
based on whether it is possible to form a non-decreasing sequence by selecting exactly k integers from the list.
5 3
4 3 5 6 1
YES
</p>