#K71462. Maxim's Winning Game

    ID: 33537 Type: Default 1000ms 256MiB

Maxim's Winning Game

Maxim's Winning Game

In this problem, you are given an array of integers and a positive integer ( k ). Your task is to determine whether it is possible to make the array non-decreasing by performing at most ( k ) swaps. Each swap can correct two mismatched positions between the current array and its sorted (non-decreasing) order.

Formally, let the array be ( a_1, a_2, \ldots, a_n ). Define ( mismatch ) as the number of indices ( i ) such that ( a_i ) does not equal the ( i^{th} ) element in the sorted array. The minimum number of swaps required is ( \lceil \frac{mismatch}{2} \rceil ). Output "Yes" if ( \lceil \frac{mismatch}{2} \rceil \leq k ); otherwise, output "No".

This problem tests your ability to analyze array properties and implement efficient algorithms under given swap constraints.

inputFormat

The input is given via standard input. The first line contains an integer ( T ) representing the number of test cases. For each test case, the first line contains two space-separated integers ( n ) and ( k ), where ( n ) is the size of the array and ( k ) is the maximum number of swaps allowed. The next line contains ( n ) space-separated integers representing the elements of the array.

outputFormat

For each test case, output a single line containing "Yes" if it is possible to make the array non-decreasing with at most ( k ) swaps, otherwise output "No".## sample

3
5 3
3 1 4 1 5
4 6
5 2 9 1
3 1
2 3 1
Yes

Yes No

</p>