CF1689A.Lex String

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

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

题目描述

Kuznecov likes art, poetry, and music. And strings consisting of lowercase English letters.

Recently, Kuznecov has found two strings, aa and bb, of lengths nn and mm respectively. They consist of lowercase English letters and no character is contained in both strings.

Let another string cc be initially empty. Kuznecov can do the following two types of operations:

  • Choose any character from the string aa, remove it from aa, and add it to the end of cc.
  • Choose any character from the string bb, remove it from bb, and add it to the end of cc.

But, he can not do more than kk operations of the same type in a row. He must perform operations until either aa or bb becomes empty. What is the lexicographically smallest possible value of cc after he finishes?

A string xx is lexicographically smaller than a string yy if and only if one of the following holds:

  • xx is a prefix of yy, but x≠yx \neq y;
  • in the first position where xx and yy differ, the string xx has a letter that appears earlier in the alphabet than the corresponding letter in yy.

库兹涅佐夫喜欢艺术、诗歌和音乐,也喜欢由小写英文字母组成的字符串。

最近,库兹涅佐夫找到了两个字符串 aa 和 bb,长度分别为 nn 和 mm。它们均由小写英文字母组成,且两个字符串中不包含任何相同的字符。

另设一个字符串 cc 初始为空。库兹涅佐夫可以执行以下两种操作:

  • 从字符串 aa 中任选一个字符,将其从 aa 中删除,并添加到 cc 的末尾;
  • 从字符串 bb 中任选一个字符,将其从 bb 中删除,并添加到 cc 的末尾。

但他在连续操作中,同一种操作最多只能执行 kk 次。他必须持续执行操作,直到 aa 或 bb 中至少有一个变为空。那么,当操作结束时,cc 可能取得的字典序最小值是多少?

字符串 xx 的字典序小于字符串 yy,当且仅当满足以下条件之一:

  • xx 是 yy 的真前缀(即 xx 是 yy 的前缀,但 x≠yx \neq y);
  • 在 xx 与 yy 首次出现不同字符的位置上,xx 中该位置的字母在字母表中早于 yy 中对应位置的字母。

输入格式

There are several test cases in the input data. The first line contains a single integer tt (1≤t≤1001 \leq t \leq 100) — the number of test cases. This is followed by the test cases description.

The first line of each test case contains three integers nn, mm, and kk (1≤n,m,k≤1001\leq n,m,k \leq 100) — parameters from the statement.

The second line of each test case contains the string aa of length nn.

The third line of each test case contains the string bb of length mm.

The strings contain only lowercase English letters. It is guaranteed that no symbol appears in aa and bb simultaneously.

输入数据包含多个测试用例。第一行包含一个整数 tt(1≤t≤1001 \leq t \leq 100),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含三个整数 nn、mm 和 kk(1≤n,m,k≤1001\leq n,m,k \leq 100),即题目中给出的参数。

每个测试用例的第二行包含一个长度为 nn 的字符串 aa。

每个测试用例的第三行包含一个长度为 mm 的字符串 bb。

字符串仅由小写英文字母组成。保证没有任何字符同时出现在 aa 和 bb 中。

输出格式

In each test case, output a single string cc — the answer to the problem.

在每个测试用例中,输出一个字符串 cc —— 该问题的答案。

输入输出样例

  • 输入#1

    3
    6 4 2
    aaaaaa
    bbbb
    5 9 3
    caaca
    bedededeb
    7 7 1
    noskill
    wxhtzdy

    输出#1

    aabaabaa
    aaabbcc
    dihktlwlxnyoz

说明/提示

In the first test case, it is optimal to take two 'a's from the string aa and add them to the string cc. Then it is forbidden to take more characters from aa, hence one character 'b' from the string bb has to be taken. Following that logic, we end up with cc being 'aabaabaa' when string aa is emptied.

In the second test case it is optimal to take as many 'a's from string aa as possible, then take as many 'b's as possible from string bb. In the end, we take two 'c's from the string aa emptying it.

在第一个测试用例中,最优策略是从字符串 aa 中取两个字符 'a' 并添加到字符串 cc 中。此后,禁止再从 aa 中取字符,因此必须从字符串 bb 中取一个字符 'b'。依此逻辑,当字符串 aa 被取空时,最终 cc 变为 'aabaabaa'。

在第二个测试用例中,最优策略是尽可能多地从字符串 aa 中取字符 'a',然后尽可能多地从字符串 bb 中取字符 'b'。最后,从字符串 aa 中取两个字符 'c',从而将其取空。

输入解题思路,AI测评打分。不知道怎么写?

首页