Advertisement
Guest User

Untitled

a guest
Feb 19th, 2016
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. // by Errichto
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4.  
  5. const int nax = 1e6 + 5;
  6. char s[nax];
  7.  
  8. int main() {
  9.     int n, k;
  10.     scanf("%d%d", &n, &k);
  11.     scanf("%s", s);
  12.     for(int i = 0; i < n; ++i) {
  13.         char best_letter = s[i];
  14.         int best_distance = 0;
  15.         for(char maybe = 'a'; maybe <= 'z'; ++maybe) {
  16.             int distance = abs(maybe - s[i]);
  17.             if(distance <= k && distance > best_distance) {
  18.                 best_distance = distance;
  19.                 best_letter = maybe;
  20.             }
  21.         }
  22.         k -= best_distance;
  23.         s[i] = best_letter;
  24.     }
  25.     if(k > 0) puts("-1");
  26.     else printf("%s\n", s);
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement