#C7336. Taco Sorting Challenge

    ID: 51196 Type: Default 1000ms 256MiB

Taco Sorting Challenge

Taco Sorting Challenge

Chef is given an array A of N distinct integers. He is allowed to perform at most K swap operations on the array. In each swap, he can exchange the positions of any two elements. Your task is to determine whether it is possible to sort the array in ascending order using at most K swap operations.

The minimum number of swaps required to sort the array can be determined by computing the sum over all cycles in the permutation: $$\sum (\text{cycle\_length} - 1)$$ If this sum does not exceed K, then the answer is YES; otherwise, it is NO.

inputFormat

The input begins with an integer T, representing the number of test cases. For each test case, the first line contains two integers N and K, where N is the size of the array and K is the maximum allowed swap operations. The second line contains N distinct integers representing the array A.

outputFormat

For each test case, output a single line containing YES if the array can be sorted in ascending order using at most K swaps; otherwise, output NO.

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

NO YES

</p>