Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // by Errichto
- #include<bits/stdc++.h>
- using namespace std;
- const int nax = 1e6 + 5;
- char s[nax];
- int main() {
- int n, k;
- scanf("%d%d", &n, &k);
- scanf("%s", s);
- for(int i = 0; i < n; ++i) {
- char best_letter = s[i];
- int best_distance = 0;
- for(char maybe = 'a'; maybe <= 'z'; ++maybe) {
- int distance = abs(maybe - s[i]);
- if(distance <= k && distance > best_distance) {
- best_distance = distance;
- best_letter = maybe;
- }
- }
- k -= best_distance;
- s[i] = best_letter;
- }
- if(k > 0) puts("-1");
- else printf("%s\n", s);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement