Phoenix Locks the Door
InterviewTime limit1sMemory limit1024 MB
Given N dials showing letters, find the lexicographically smallest string after turning single dials exactly K times, with each turn advancing a letter and wrapping Z to A.
- Level
Medium5 of 10
- Topics
- Greedy, String, Implementation
- Solved
- No attempts yet
Problem
Where is Phoenix's house? People assume Phoenix lives at POSTECH, but he actually lives in the Phoenix village high in the sky. Outsiders can hardly reach the village, and since phoenixes are born righteous, they often forget to lock their doors.
Phoenix is no exception. Every day he travels between POSTECH and the village without locking his door. One day, while Phoenix was away from home, Mr. K, a famous thief from POSTECH, installed a lock on Phoenix's house! The lock is made of dials connected together, and each dial has the uppercase letters A through Z written in order.
To open the lock, Phoenix can pick one dial and turn it step. The letter shown on the chosen dial changes from A to B, B to C, ..., and Z to A. Dials cannot be turned in the opposite direction. Phoenix has learned that the password is the lexicographically smallest string he can display after performing exactly turns. Help Phoenix get his house back by finding the password.
Input
The first line contains the length of the lock and the number of turns , separated by a space.
The second line contains the string of length currently shown on the lock. consists only of uppercase letters.
Output
Print the lexicographically smallest string that can be displayed by turning the dials exactly times.
Hint
For two strings and of the same length , is lexicographically smaller than if there is an integer that satisfies the following conditions.
- for all
- , and comes before in alphabetical order.