GUPTA MECHANICAL

IN THIS WEBSITE I CAN TELL ALL ABOUT TECH. TIPS AND TRICKS APP REVIEWS AND UNBOXINGS ALSO TECH. NEWS .............

Friday 10 June 2022

[Solution] Lex String Codeforces Solution | Codeforces Problem Solution 2022

A. Lex String
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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

Recently, Kuznecov has found two strings, a and b, of lengths n and m respectively. They consist of lowercase English letters and no character is contained in both strings.

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

  • Choose any character from the string a, remove it from a, and add it to the end of c.
  • Choose any character from the string b, remove it from b, and add it to the end of c.

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

Solution Click Below:-  CLICK HERE


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

    • x is a prefix of y, but xy;
    • in the first position where x and y differ, the string x has a letter that appears earlier in the alphabet than the corresponding letter in y.
    Input
    There are several test cases in the input data. The first line contains a single integer t (1t100) — the number of test cases. This is followed by the test cases description.

    The first line of each test case contains three integers nm, and k (1n,m,k100) — parameters from the statement.

    The second line of each test case contains the string a of length n.

    The third line of each test case contains the string b of length m.

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

    Output

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

    No comments:

    Post a Comment