CF1348C.Phoenix and Distribution

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Phoenix has a string ss consisting of lowercase Latin letters. He wants to distribute all the letters of his string into kk non-empty strings a1,a2,,aka_1, a_2, \dots, a_k such that every letter of ss goes to exactly one of the strings aia_i . The strings aia_i do not need to be substrings of ss . Phoenix can distribute letters of ss and rearrange the letters within each string aia_i however he wants.

For example, if $s = $ baba and k=2k=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 ( aia_i should be non-empty)

Phoenix wants to distribute the letters of his string ss into kk strings a1,a2,,aka_1, a_2, \dots, a_k to minimize the lexicographically maximum string among them, i. e. minimize max(a1,a2,,ak)max(a_1, a_2, \dots, a_k) . Help him find the optimal distribution and print the minimal possible value of max(a1,a2,,ak)max(a_1, a_2, \dots, a_k) .

String xx is lexicographically less than string yy if either xx is a prefix of yy and xyx \ne y , or there exists an index ii ( 1imin(x,y))1 \le i \le min(|x|, |y|)) such that xix_i < yiy_i and for every jj (1j<i)(1 \le j < i) xj=yjx_j = y_j . Here x|x| denotes the length of the string xx .

输入格式

The input consists of multiple test cases. The first line contains an integer tt ( 1t10001 \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 nn and kk ( 1kn1051 \le k \le n \le 10^5 ) — the length of string ss and the number of non-empty strings, into which Phoenix wants to distribute letters of ss , respectively.

The second line of each test case contains a string ss of length nn consisting only of lowercase Latin letters.

It is guaranteed that the sum of nn over all test cases is 105\le 10^5 .

输出格式

Print tt answers — one per test case. The ii -th answer should be the minimal possible value of max(a1,a2,,ak)max(a_1, a_2, \dots, a_k) in the ii -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

说明/提示

In the first test case, one optimal solution is to distribute baba into ab and ab.

In the second test case, one optimal solution is to distribute baacb into abbc and a.

In the third test case, one optimal solution is to distribute baacb into ac, ab, and b.

In the fourth test case, one optimal solution is to distribute aaaaa into aa, aa, and a.

In the fifth test case, one optimal solution is to distribute aaxxzz into az, az, x, and x.

In the sixth test case, one optimal solution is to distribute phoenix into ehinopx.

首页