Company: Google
Difficulty: hard
Every evening, the keeper of the Saltmere lighthouse raises a sequence of signal flags along the harbour mast. Each flag contains one lowercase letter, and the flags remain in the order in which they were raised. The glow strength of a flag is determined by its letter: the letter a has strength 1, b has strength 2, and so on up to z , which has strength 26. The harbour authority requires the keeper to select exactly k flags from the sequence without changing their original order. The total glow strength of the selected flags must be at least f . Among all selections that satisfy these conditions, determine the lexicographically smallest string formed by the selected flags. Input Format The first line contains a single integer n , the number of flags. The second line contains the string s of exactly n lowercase English letters. The third line contains a single integer k , the number of flags that must be selected. The fourth line contains a single integer f , the minimum required glow s