Codeforces Round 1011 (Div. 2)
A
Serval and String Theory
Codeforces
900
原题
←B →
翻译中…

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

翻译中…

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

翻译中…
  • Choose two indices $i$ and $j$ ($1\le i,j\le n$), then swap $s_i$ and $s_j$. Note that if $i=j$, you do nothing.
翻译中…

Determine whether you can make $s$ universal by performing the above operation at most $k$ times.

翻译中…

$^{\text{∗}}$A string $a$ is lexicographically smaller than a string $b$ of the same length, if and only if the following holds: in the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$. $^{\text{†}}$The reversal of a string $r$ is the string obtained by writing $r$ from right to left. For example, the reversal of the string $\texttt{abcad}$ is $\texttt{dacba}$.

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

The second line contains a string $s$ consisting of $n$ lowercase Latin letters.

翻译中…

Output

翻译中…

For each test case, print "YES" if it is possible to make $s$ universal by performing the operation at most $k$ 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, $s$ will keep the same after any operations. However, the reversal of $\texttt{a}$ is still $\texttt{a}$, so it is impossible to make $s$ universal.

翻译中…

In the second test case, the string $\texttt{rev}$ is lexicographically smaller than $\texttt{ver}$. Thus, $s$ is already universal.

翻译中…

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

翻译中…
  1. Swap $s_4$ and $s_7$. After this operation, $s$ becomes $\texttt{uniserval}$;
  2. Swap $s_1$ and $s_3$. After this operation, $s$ becomes $\texttt{inuserval}$.
翻译中…

And the string $\texttt{inuserval}$ is universal.

翻译中…

样例

Input #1
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
Output #1
NO
YES
NO
YES
YES
NO
YES
NO
InputCopy OutputCopy
题目信息
题号
2085A
时间限制
1 s
内存限制
256 MB
标签
构造
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。