#K43197. Unlocking the Sequence

    ID: 27256 Type: Default 1000ms 256MiB

Unlocking the Sequence

Unlocking the Sequence

You are given an array of n integers and a number k which represents the maximum number of swap operations allowed. In each swap operation, you can swap any two elements of the array. Note that a single swap operation can potentially fix two misplaced elements.

Your task is to determine whether it is possible to rearrange the given array into strictly increasing order using at most k swap operations. To decide this, first compute the number of mismatches between the original array and its sorted version. Let \(swap\_count = \sum_{i=0}^{n-1} [a_i \neq sorted(a)_i]\). Since each swap can fix two elements, if \(\lfloor swap\_count/2 \rfloor \leq k\), then the rearrangement is possible; otherwise, it is not.

inputFormat

The first line of the input contains an integer \(t\) (the number of test cases). Each test case consists of two lines:

  • The first line contains two integers \(n\) and \(k\): the size of the array and the maximum number of swap operations allowed.
  • The second line contains \(n\) space-separated integers representing the array elements.

outputFormat

For each test case, output a single line containing "YES" if it is possible to rearrange the array into strictly increasing order using at most \(k\) swap operations, otherwise output "NO".

## sample
3
5 2
4 3 1 5 2
6 0
6 5 4 3 2 1
3 3
3 2 1
YES

NO YES

</p>