Lexicographically Smallest String
Time Limit: 1.0 s
Memory Limit: 256.0 MB
You are given a string S containing n characters. You need to find out the lexicographically smallest string after performing at most m operations (possibly zero).
In each operation, you can select two indices i and j (\(1 \le i,j \le n\)), and swap their characters. For example, for S = "abaa"
, if you select indices 1 and 2, then swap(S[1]
, S[2]
). After the swap, the string becomes S="baaa"
.
Input
First line contains a positive integers T, which denotes number of test cases.
In each test case, the first line contains n and m, the length of the string and the number of operations, respectively.
The second line contains the string S of length n.
\(1 \le T \le 10^4\)
\(1 \le n \le 10^5\)
\(1 \le m \le 10^9\)
Note: String S contains english lowercase alphabet only. It is guranteed that sum of n over all test cases doesn't exceed \(2 \times 10^5\).
Output
For each test case, print the lexicographically smallest string S after performing at most m operations.
Sample
Input | Output |
---|---|
|
|
Information
- ID
- 1058
- Difficulty
- 8
- Category
- (None)
- Tags
- (None)
- # Submissions
- 35
- Accepted
- 4
- Accepted Ratio
- 11%
- Uploaded By
Related
In following contests: