#P10910. [蓝桥杯 2024 国 B] 最小字符串

[蓝桥杯 2024 国 B] 最小字符串

Problem Description

Given a string SS of length NN that contains only lowercase letters, and MM lowercase letters c1,c2,,cMc_1, c_2, \cdots, c_M. Now you need to insert all MM lowercase letters into the string SS, and each lowercase letter can be inserted at any position.

What is the lexicographically smallest string you can obtain?

Input Format

The first line contains two integers NN and MM.

The second line contains a string SS of length NN.

The third line contains MM lowercase letters c1,c2,,cMc_1, c_2, \cdots, c_M.

Output Format

Output a string of length N+MN + M as the answer.

4 3
abbc
cba
aabbbcc
7 3
lanqiao
bei
beilanqiao

Hint

【Test case scale and constraints】

For 20%20\% of the test cases, M=1M = 1.

For 100%100\% of the test cases, 1N,M1051 \le N, M \le 10^5.

Translated by ChatGPT 5