-
-
Save zaltoprofen/b8b1ae321f3151085758116dbd068290 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
"strconv" | |
) | |
func min(s []byte, k int64) (int, int64) { | |
sl := len(s) | |
for i := 0; i < sl; i++ { | |
if s[i] == 'a' { | |
continue | |
} | |
if int64(('z'+1)-s[i]) <= k { | |
diff := 'z' + 1 - s[i] | |
s[i] = 'a' | |
return i, k - int64(diff) | |
} | |
} | |
s[sl-1] += byte(k % 26) | |
return -1, 0 | |
} | |
func main() { | |
in := bufio.NewReader(os.Stdin) | |
s, _ := in.ReadString(byte('\n')) | |
s = s[:len(s)-1] | |
kstr, _ := in.ReadString(byte('\n')) | |
kstr = kstr[:len(kstr)-1] | |
k, _ := strconv.ParseInt(kstr, 10, 64) | |
b := []byte(s) | |
i := 0 | |
for k > 0 { | |
var v int | |
v, k = min(b[i:], k) | |
i += v | |
} | |
fmt.Println(string(b)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment