Limits
1.5s, 128 MB

In the match between Bangladesh vs Zimbabwe, Bangladeshi wicket-keeper Nurul Hasan made a silly mistake in the last ball and almost compromised team’s win. After the match, Captain Sakib-Al Hasan was angry at Nurul. So, he asked Man of the match winner Taskin Ahmed to give a permutation of integers $1,2,3,….,n$. Sakib gave the permutation to Nurul and an integer $m$ and told him to sort the array in increasing order using only one move which is:

- Choose a subset of size
**at most**$m$ from the array and move it to the beginning or ending of the array without changing the order. For more details read the explanation of the first test case below.

Now find out if Nurul will be able to sort the array in increasing order. Note that he can make only one move.

A permutation of $n$ integers is an array where each integers between $1$ and $n$ exactly once and in any order.$[2,1,3,4]$ and $[1,2,3]$ are permutations where $[1,2,2]$ and $[2,5,3,4]$ aren’t.

A subset of an array can be obtained by deleting some elements(can be none or all) from the array. Deleting elements are not necessarily consecutive.$[2,1]$ and $[2,3]$ are some of the subsets of $[2,1,3,4]$ while $[1,2]$ is not.

First line of input will contains an integer $T(1 \leq T \leq 10^5)$.

Each test case contains two lines. In first line there will be two integers $n(1 \leq n \leq 10^5)$ and $m(0 \leq m \leq n)$.

Second line will contain an array $n$ integers. It is guaranteed that the array is a permutation of $n$.

Sum of $n$ over all test cases won’t exceed $10^5$.

For each test case, Print $Yes$ if Nurul Hasan will be able to sort the array in increasing order using exactly one move else print $No$.

Input | Output |
---|---|

2 5 2 4 1 5 2 3 5 1 4 1 5 2 3 | Yes No |

For first test case, Nurul Hasan can take the subset $[4,5]$ and put it in back of the array or take the subset $[1,2,3]$ and put it on front. As $m=2$, he will have to go with the first choice. |

Login to submit.

56%
Solution Ratio

fahimcp495Earliest,

Sahil.764169Fastest, 0.0s

nusuBotLightest, 4.9 MB

HilariaShortest, 602B

Toph uses cookies. By continuing you agree to our Cookie Policy.