#C8075. Reverse Operations Sorting Game

    ID: 52017 Type: Default 1000ms 256MiB

Reverse Operations Sorting Game

Reverse Operations Sorting Game

Given an integer array of length n and an integer k representing the number of reverse operations allowed, determine if it is possible to sort the array in non-decreasing order using exactly k reverse operations.

A reverse operation is defined as taking a contiguous subarray and reversing its order. In particular:

  • If k = 0, the array must already be sorted (i.e. if the array is \(A\) and its sorted order is \(S\), then \(A = S\)).
  • If k = 1, then in addition to the already sorted case, the array can be sorted if it is exactly the reverse of the sorted order (i.e. \(A = S^r\)).
  • If k \ge 2, then it is always possible to sort the array using such operations.

You are required to output YES if the array can be sorted under the given conditions, and NO otherwise.

The mathematical conditions can be summarized as follows:

\[ \text{if } k = 0: A = S, \quad \text{if } k = 1: A = S \text{ or } A = S^r, \quad \text{if } k \ge 2: \text{always YES} \]

inputFormat

The first line contains two integers n and k separated by a space.

The second line contains n integers denoting the elements of the array, separated by spaces.

outputFormat

Output a single line containing YES if it is possible to sort the array in exactly k reverse operations, and NO otherwise.

## sample
5 1
5 4 3 2 1
YES

</p>