#C1334. Sort Array with Limited Operations
Sort Array with Limited Operations
Sort Array with Limited Operations
You are given an array of N integers and an integer K, representing the maximum number of allowed adjacent swap operations. The minimum number of adjacent swaps required to sort the array is equal to the number of inversions in the array. You need to determine if it is possible to sort the array in at most K operations.
Mathematically, if the number of inversions in the array is \(I\), then sorting is possible if and only if \(I \leq K\).
inputFormat
The input is read from stdin and consists of two lines:
- The first line contains two space-separated integers: N (the number of elements in the array) and K (the maximum number of allowed adjacent swap operations).
- The second line contains N space-separated integers representing the elements of the array.
outputFormat
Output a single line to stdout with either "YES" if the array can be sorted within K operations or "NO" otherwise.
## sample5 5
3 1 2 5 4
YES