CF2085A.Serval and String Theory

传统题 时间 2000 ms 内存 256 MiB 4 尝试 1 已通过 1 标签

Serval and String Theory

A string rr consisting only of lowercase Latin letters is called universal if and only if rr is lexicographically smaller^{\text{∗}} than the reversal^{\text{†}} of rr.

You are given a string ss consisting of nn lowercase Latin letters. You are required to make ss universal. To achieve this, you can perform the following operation on ss at most kk times:

  • Choose two indices ii and jj (1i,jn1\le i,j\le n), then swap sis_i and sjs_j. Note that if i=ji=j, you do nothing.

Determine whether you can make ss universal by performing the above operation at most kk times.

^{\text{∗}}A string aa is lexicographically smaller than a string bb of the same length, if and only if the following holds:

  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb.

^{\text{†}}The reversal of a string rr is the string obtained by writing rr from right to left. For example, the reversal of the string abcad is dacba.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t5001 \le t \le 500). The description of the test cases follows.

The first line of each test case contains two integers nn and kk (1n1001\le n\le 100, 0k1040\le k\le 10^4) — the length of the string ss, and the maximum number of operations you can perform.

The second line contains a string ss consisting of nn lowercase Latin letters.

Output

For each test case, print "YES" if it is possible to make ss universal by performing the operation at most kk times. Otherwise, print "NO".

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Note

In the first test case, ss will keep the same after any operations. However, the reversal of a is still a, so it is impossible to make ss universal.

In the second test case, the string rev is lexicographically smaller than ver. Thus, ss is already universal.

In the fifth test case, you can perform the operations as follows:

  1. Swap s4s_4 and s7s_7. After this operation, ss becomes uniserval;
  2. Swap s1s_1 and s3s_3. After this operation, ss becomes inuserval.

And the string inuserval is universal.

Samples

8
1 10000
a
3 3
rev
6 0
string
6 0
theory
9 2
universal
19 0
codeforcesecrofedoc
19 1
codeforcesecrofedoc
3 1
zzz
NO
YES
NO
YES
YES
NO
YES
NO

在线编程 IDE

建议全屏模式获得最佳体验