All submissions for this problem are available.Gru has a string $S$ of length $N$, consisting of only characters $a$ and $b$ for banana and $P$ points to spend. Now Gru wants to replace and/or re-arrange characters of this given string to get the lexicographically smallest string possible. For this, he can perform the following two operations any number of times. 1) Swap any two characters in the string. This operation costs $1$ $point$. (any two, need not be adjacent) 2) Replace a character in the string with any other lower case english letter. This operation costs $2$ $points$. Help Gru in obtaining the lexicographically smallest string possible, by using at most $P$ points. ###Input: - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains two lines of input, first-line containing two integers $N$ , $P$. - The second line contains a string $S$ consisting of $N$ characters. ###Output: For each testcase, output in a single containing the lexicographically smallest string obtained. ###Constraints - $1 \leq T \leq 10$ - $1 \leq N \leq 10^5$ - $0 \leq P \leq 2N$ - $S$ only consists of $'a'$ and $'b'$ ###Sample Input: 1 3 3 bba ###Sample Output: aab ###Explanation: We swap $S$ and $S$, to get $abb$. With the 2 remaining points, we replace $S$ to obtain $aab$ which is the lexicographically smallest string possible for this case.
|Tags||enigma, greedy, kabeer27, medium, plit2020|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, rust, SCALA, swift, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, SQL, kotlin, PERL6, TEXT, SCM chicken, PYP3, CLOJ, R, COB, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.