#K66427. Sorting by Reordering Subarrays
Sorting by Reordering Subarrays
Sorting by Reordering Subarrays
You are given an array consisting of n integers and an integer k. Your task is to determine if it is possible to split the array into exactly k non-empty contiguous subarrays, then reorder these subarrays arbitrarily, and finally merge them back into a single array that is strictly increasing.
Definition: Let the array be \(a_1, a_2, \dots, a_n\). You can divide it into exactly k contiguous segments. After rearranging these segments in any order and concatenating them, the resulting array should satisfy \(a_1 < a_2 < \dots < a_n\).
If \(k \ge n\), a solution is trivial since you can split the array into individual elements.
Determine whether such a reordering exists for each provided test case.
inputFormat
The first line of input contains an integer t (the number of test cases).
Each test case consists of two lines:
- The first line contains two integers: n (the length of the array) and k (the number of subarrays you must split the array into).
- The second line contains n space-separated integers representing the array.
All input is provided via standard input (stdin).
outputFormat
For each test case, output a single line containing either YES
if it is possible to achieve a strictly increasing sequence by appropriately reordering the subarrays, or NO
if it is not possible.
Output should be written to standard output (stdout).
## sample1
1 1
5
YES
</p>