Problem p03994 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  map<int, char> m;
  m['a'] = 0;
  m['z'] = 1;
  m['y'] = 2;
  m['x'] = 3;
  m['w'] = 4;
  m['v'] = 5;
  m['u'] = 6;
  m['t'] = 7;
  m['s'] = 8;
  m['r'] = 9;
  m['q'] = 10;
  m['p'] = 11;
  m['o'] = 12;
  m['n'] = 13;
  m['m'] = 14;
  m['l'] = 15;
  m['k'] = 16;
  m['j'] = 17;
  m['i'] = 18;
  m['h'] = 19;
  m['g'] = 20;
  m['f'] = 21;
  m['e'] = 22;
  m['d'] = 23;
  m['c'] = 24;
  m['b'] = 25;
  string s;
  int n;
  cin >> s >> n;
  for (int i = 0; i < s.size(); i++) {
    if (m[s[i]] <= n) {
      n -= m[s[i]];
      s[i] = 'a';
    }
    if (n == 0)
      break;
  }
  if (n > 0) {
    for (int i = 0; i < n; i++) {
      // cout << s[s.size()-1] << endl;
      if (s[s.size() - 1] == 'z')
        s[s.size() - 1] = 'a';
      else if (s[s.size() - 1] == 'a')
        s[s.size() - 1] = 'b';
      else if (s[s.size() - 1] == 'b')
        s[s.size() - 1] = 'c';
      else if (s[s.size() - 1] == 'c')
        s[s.size() - 1] = 'd';
      else if (s[s.size() - 1] == 'd')
        s[s.size() - 1] = 'e';
      else if (s[s.size() - 1] == 'e')
        s[s.size() - 1] = 'f';
      else if (s[s.size() - 1] == 'f')
        s[s.size() - 1] = 'g';
      else if (s[s.size() - 1] == 'g')
        s[s.size() - 1] = 'h';
      else if (s[s.size() - 1] == 'h')
        s[s.size() - 1] = 'i';
      else if (s[s.size() - 1] == 'i')
        s[s.size() - 1] = 'j';
      else if (s[s.size() - 1] == 'j')
        s[s.size() - 1] = 'k';
      else if (s[s.size() - 1] == 'k')
        s[s.size() - 1] = 'l';
      else if (s[s.size() - 1] == 'l')
        s[s.size() - 1] = 'm';
      else if (s[s.size() - 1] == 'm')
        s[s.size() - 1] = 'n';
      else if (s[s.size() - 1] == 'n')
        s[s.size() - 1] = 'o';
      else if (s[s.size() - 1] == 'o')
        s[s.size() - 1] = 'p';
      else if (s[s.size() - 1] == 'p')
        s[s.size() - 1] = 'q';
      else if (s[s.size() - 1] == 'q')
        s[s.size() - 1] = 'r';
      else if (s[s.size() - 1] == 'r')
        s[s.size() - 1] = 's';
      else if (s[s.size() - 1] == 's')
        s[s.size() - 1] = 't';
      else if (s[s.size() - 1] == 't')
        s[s.size() - 1] = 'u';
      else if (s[s.size() - 1] == 'u')
        s[s.size() - 1] = 'v';
      else if (s[s.size() - 1] == 'v')
        s[s.size() - 1] = 'w';
      else if (s[s.size() - 1] == 'w')
        s[s.size() - 1] = 'x';
      else if (s[s.size() - 1] == 'x')
        s[s.size() - 1] = 'y';
      else if (s[s.size() - 1] == 'y')
        s[s.size() - 1] = 'z';
    }
  }
  cout << s << endl;
  return 0;
}


Fixed submission:
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main() {
  map<int, char> m;
  m['a'] = 0;
  m['z'] = 1;
  m['y'] = 2;
  m['x'] = 3;
  m['w'] = 4;
  m['v'] = 5;
  m['u'] = 6;
  m['t'] = 7;
  m['s'] = 8;
  m['r'] = 9;
  m['q'] = 10;
  m['p'] = 11;
  m['o'] = 12;
  m['n'] = 13;
  m['m'] = 14;
  m['l'] = 15;
  m['k'] = 16;
  m['j'] = 17;
  m['i'] = 18;
  m['h'] = 19;
  m['g'] = 20;
  m['f'] = 21;
  m['e'] = 22;
  m['d'] = 23;
  m['c'] = 24;
  m['b'] = 25;
  string s;
  int n;
  cin >> s >> n;
  for (int i = 0; i < s.size(); i++) {
    if (m[s[i]] <= n) {
      n -= m[s[i]];
      s[i] = 'a';
    }
    if (n == 0)
      break;
  }
  n %= 26;
  if (n > 0) {
    for (int i = 0; i < n; i++) {
      // cout << s[s.size()-1] << endl;
      if (s[s.size() - 1] == 'z')
        s[s.size() - 1] = 'a';
      else if (s[s.size() - 1] == 'a')
        s[s.size() - 1] = 'b';
      else if (s[s.size() - 1] == 'b')
        s[s.size() - 1] = 'c';
      else if (s[s.size() - 1] == 'c')
        s[s.size() - 1] = 'd';
      else if (s[s.size() - 1] == 'd')
        s[s.size() - 1] = 'e';
      else if (s[s.size() - 1] == 'e')
        s[s.size() - 1] = 'f';
      else if (s[s.size() - 1] == 'f')
        s[s.size() - 1] = 'g';
      else if (s[s.size() - 1] == 'g')
        s[s.size() - 1] = 'h';
      else if (s[s.size() - 1] == 'h')
        s[s.size() - 1] = 'i';
      else if (s[s.size() - 1] == 'i')
        s[s.size() - 1] = 'j';
      else if (s[s.size() - 1] == 'j')
        s[s.size() - 1] = 'k';
      else if (s[s.size() - 1] == 'k')
        s[s.size() - 1] = 'l';
      else if (s[s.size() - 1] == 'l')
        s[s.size() - 1] = 'm';
      else if (s[s.size() - 1] == 'm')
        s[s.size() - 1] = 'n';
      else if (s[s.size() - 1] == 'n')
        s[s.size() - 1] = 'o';
      else if (s[s.size() - 1] == 'o')
        s[s.size() - 1] = 'p';
      else if (s[s.size() - 1] == 'p')
        s[s.size() - 1] = 'q';
      else if (s[s.size() - 1] == 'q')
        s[s.size() - 1] = 'r';
      else if (s[s.size() - 1] == 'r')
        s[s.size() - 1] = 's';
      else if (s[s.size() - 1] == 's')
        s[s.size() - 1] = 't';
      else if (s[s.size() - 1] == 't')
        s[s.size() - 1] = 'u';
      else if (s[s.size() - 1] == 'u')
        s[s.size() - 1] = 'v';
      else if (s[s.size() - 1] == 'v')
        s[s.size() - 1] = 'w';
      else if (s[s.size() - 1] == 'w')
        s[s.size() - 1] = 'x';
      else if (s[s.size() - 1] == 'x')
        s[s.size() - 1] = 'y';
      else if (s[s.size() - 1] == 'y')
        s[s.size() - 1] = 'z';
    }
  }
  cout << s << endl;
  return 0;
}