CF1737A.Ela Sorting Books

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Ela loves reading a lot, just like her new co-workers in DTL! On her first day after becoming an engineer in DTL, she is challenged by a co-worker to sort a heap of books into different compartments on the shelf. nn books must be split into kk compartments on the bookshelf ( nn is divisible by kk ). Each book is represented by a lowercase Latin letter from 'a' to 'y' inclusively, which is the beginning letter in the title of the book.

Ela must stack exactly nk\frac{n}{k} books in each compartment. After the books are stacked, for each compartment indexed from 11 to kk , she takes the minimum excluded (MEX) letter of the multiset of letters formed by letters representing all books in that compartment, then combines the resulting letters into a string. The first letter of the resulting string is the MEX letter of the multiset of letters formed by the first compartment, the second letter of the resulting string is the MEX letter of the multiset of letters formed by the second compartment, ... and so on. Please note, under the constraint of this problem, MEX letter can always be determined for any multiset found in this problem because 'z' is not used.

What is the lexicographically greatest resulting string possible that Ela can create?

A string aa is lexicographically greater than a string bb if and only if one of the following holds:

  • bb is a prefix of aa , but bab \ne a ;
  • in the first position where aa and bb differ, the string aa has a letter that appears later in the alphabet than the corresponding letter in bb .

The minimum excluded (MEX) letter of a multiset of letters is the letter that appears earliest in the alphabet and is not contained in the multiset. For example, if a multiset of letters contains 77 letters 'b', 'a', 'b', 'c', 'e', 'c', 'f' respectively, then the MEX letter of this compartment is 'd', because 'd' is not included in the multiset, and all letters comes before 'd' in the alphabet, namely 'a', 'b' and 'c', are included in the multiset.

输入格式

Each test contains multiple test cases. The first line contains the number of test cases tt ( 1t1001 \le t \le 100 ). Description of the test cases follows.

The first line of each test case contains two integers nn and kk ( 1n2001 \le n \le 200 ; 1kn1 \le k \le n ). It is guaranteed that nn is divisible by kk .

The second line of each test case contains a string of nn lowercase Latin letters from 'a' to 'y' inclusively. Each letter represents the starting letter of the title of a book in the initial heap.

It is guaranteed that the sum of nn over all test cases does not exceed 10001000 .

输出格式

For each test case, output a string of kk letters which is the most optimal string that Ela can find.

输入输出样例

  • 输入#1

    5
    12 3
    cabccadabaac
    12 6
    cabccadabaac
    12 12
    cabccadabaac
    25 1
    abcdefghijklmnopqrstuvwxy
    10 5
    bcdxedbcfg

    输出#1

    edb
    ccbbba
    bbbbbaaaaaaa
    z
    aaaaa

说明/提示

In the first test case, the books can be divided into 33 compartments as below:

  • the first compartment contains the books with indices 1,2,3,71, 2, 3, 7 : multiset1={multiset_1 = \{ 'c', 'a', 'b', 'd' }\} \rightarrow MEX(multiset1)=MEX(multiset_1) = 'e'
  • the second compartment contains the books with indices 4,5,6,94, 5, 6, 9 : multiset2={multiset_2 = \{ 'c', 'c', 'a', 'b' }\} \rightarrow MEX(multiset2)=MEX(multiset_2) = 'd'
  • the third compartment contains the remaining books 8,10,11,128, 10, 11, 12 : multiset3={multiset_3 = \{ 'a', 'a', 'a', 'c' }\} \rightarrow MEX(multiset3)=MEX(multiset_3) = 'b'

Therefore, the answer is 'edb'. It can be proven that there is no way that Ela can arrange the books so that it results in a lexicographically greater string.

首页