Smallest chosen word

3.2

90 votes
Algorithms, Greedy Algorithms
Problem

You are given three strings s1, s2, and s3. Let x be any subsequence of s2 (x can be an empty string). The name is in the form of (s1+x+s3), here (+) means concatenation of strings. You are required to print the lexicographically-smallest string s.

Note: The string contains only lowercase letters.

Input format

  • First line: Three numbers denoting the size of s1, s2, and s3 respectively
  • Second line: Three strings s1, s2, and s3

Output format

Print a lexicographically-smallest string.

Constraints

|s1|,|s2|,|s3|105

Sample Input
3 3 3
abc def ghi
Sample Output
abcdefghi
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Here x is "def "

Editor Image

?