#P10836. Minimizing Lexicographical Order of String A
Minimizing Lexicographical Order of String A
Minimizing Lexicographical Order of String A
You are given two strings a and b of length n, each consisting only of lowercase letters and the character '#' . The total number of '#' characters in a and b is m. You will perform exactly m operations. In the i-th operation (1-indexed), you are given a letter defined by the formula $\displaystyle \ell_i = \text{the }((i-1) \bmod 26) + 1\text{-th lowercase letter}$ (i.e. for i = 1, letter is 'a'; for i = 2, letter is 'b'; and so on, wrapping around after 'z').
In each operation, you must choose one of the two strings that still contains at least one '#' and replace its leftmost '#' with . You cannot choose a string that does not contain any '#' characters.
Your goal is to minimize the lexicographical order of string a after all operations are performed. In other words, you have full control over which string (a or b) to operate on at each step, and you want the resulting string a to be as lexicographically small as possible.
Determine the final string a after m operations under an optimal strategy.
inputFormat
The first line contains an integer n, the length of the strings. The next line contains the string a. The following line contains the string b. It is guaranteed that both strings contain only lowercase English letters and '#' characters, and together they contain exactly m '#' characters.
outputFormat
Output the final version of string a after performing all m operations optimally.
sample
5
#b#cd
a#xyz
abbcd