#abc215c. C - One More aab aba baa

C - One More aab aba baa

Score : 300300 points

问题陈述

寻找字符串 SS 的所有排列中第 KK 个字典序最小的字符串。

什么是字符串的排列?如果字符串 AA 中任意字符出现的次数与字符串 BB 中相同,那么称字符串 AA 是字符串 BB 的一个排列。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

Find the KK-th lexicographically smallest string among the strings that are permutations of a string SS.

What is a permutation of a string?A string AA is said to be a permutation of a string BB when any character occurs the same number of times in AA and BB.

Constraints

  • 1S81 \le |S| \le 8
  • SS consists of lowercase English letters.
  • There are at least KK distinct strings that are permutations of SS.

Input

Input is given from Standard Input in the following format:

SS KK

Output

Print the answer.

Sample Input 1

aab 2

Sample Output 1

aba

There are three permutations of a string aab: {\{ aab, aba, baa }\}. The 22-nd lexicographically smallest of them is aba.

Sample Input 2

baba 4

Sample Output 2

baab

Sample Input 3

ydxwacbz 40320

Sample Output 3

zyxwdcba

update @ 2024/3/10 09:32:43