The smallest string

3.2

33 votes
Algorithms, Basics of Greedy Algorithms, Greedy Algorithms
Problem

You are given a string S which consists of lower case Latin letters and you need to perform the following operation exactly K times:

  • Select any character and replace it with its next character ['a' with 'b', 'b' with 'c'.... 'z' with 'a'].

You need to find the lexicographically smallest string after performing exactly K operations on string S.

Input format

  • The first line contains an integer T denoting the number of test cases. 
  • The first line of each test case contains two space-separated integers N and K denoting the length of string S and the number of operations to be performed respectively.
  • The second line of each test case contains string S consisting of lower case Latin letters.

Output format

Print T lines. For each test case, print a single lexicographic string S after performing exactly K operations.

Constraints

1T20000

1N200000

1K1e9

String S consists of lower case Latin letters

Sum of N over all test cases will not exceed 200000

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
  1. We have 3 operations in first case so following transistion will take place x->y->z->a
  2. We have 3 operations in second case:
  •              First character z->a (1 operation)
  •              Second character y->z->a (2 operations)

 We can not have  any lexicographically smaller strings then the above obtained.

Editor Image

?