307379: CF1348C. Phoenix and Distribution
Memory Limit:256 MB
Time Limit:2 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Phoenix and Distribution
题意翻译
将给出的字符串分成若干个部分,每部分不重复、不需要连续或者按顺序。 如字符串"abbac"可以被分成"acb"和"ab"。 求长度为$n$的字符串$s$分成$k$个部分,$k$部分中字典序最大的最小字典序。 translate by luogu @$\text{longer\_name}$题目描述
Phoenix has a string $ s $ consisting of lowercase Latin letters. He wants to distribute all the letters of his string into $ k $ non-empty strings $ a_1, a_2, \dots, a_k $ such that every letter of $ s $ goes to exactly one of the strings $ a_i $ . The strings $ a_i $ do not need to be substrings of $ s $ . Phoenix can distribute letters of $ s $ and rearrange the letters within each string $ a_i $ however he wants. For example, if $ s = $ baba and $ k=2 $ , Phoenix may distribute the letters of his string in many ways, such as: - ba and ba - a and abb - ab and ab - aa and bb But these ways are invalid: - baa and ba - b and ba - baba and empty string ( $ a_i $ should be non-empty) Phoenix wants to distribute the letters of his string $ s $ into $ k $ strings $ a_1, a_2, \dots, a_k $ to minimize the lexicographically maximum string among them, i. e. minimize $ max(a_1, a_2, \dots, a_k) $ . Help him find the optimal distribution and print the minimal possible value of $ max(a_1, a_2, \dots, a_k) $ . String $ x $ is lexicographically less than string $ y $ if either $ x $ is a prefix of $ y $ and $ x \ne y $ , or there exists an index $ i $ ( $ 1 \le i \le min(|x|, |y|)) $ such that $ x_i $ < $ y_i $ and for every $ j $ $ (1 \le j < i) $ $ x_j = y_j $ . Here $ |x| $ denotes the length of the string $ x $ .输入输出格式
输入格式
The input consists of multiple test cases. The first line contains an integer $ t $ ( $ 1 \le t \le 1000 $ ) — the number of test cases. Each test case consists of two lines. The first line of each test case consists of two integers $ n $ and $ k $ ( $ 1 \le k \le n \le 10^5 $ ) — the length of string $ s $ and the number of non-empty strings, into which Phoenix wants to distribute letters of $ s $ , respectively. The second line of each test case contains a string $ s $ of length $ n $ consisting only of lowercase Latin letters. It is guaranteed that the sum of $ n $ over all test cases is $ \le 10^5 $ .
输出格式
Print $ t $ answers — one per test case. The $ i $ -th answer should be the minimal possible value of $ max(a_1, a_2, \dots, a_k) $ in the $ i $ -th test case.
输入输出样例
输入样例 #1
6
4 2
baba
5 2
baacb
5 3
baacb
5 3
aaaaa
6 4
aaxxzz
7 1
phoenix
输出样例 #1
ab
abbc
b
aa
x
ehinopx