Problem p02629 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n)                                                            \\
  for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
// const double PI = acos(-1);
const int mod = 1000000007;
int cnt = 0;

void show_vect(vector<int> v) {
  tr(it, v) { cout << *it << " "; }
  cout << endl;
}
bool isPowerOfTwo(int x) {
  /* First x in the below expression is for the case when x is 0 */
  return x && (!(x & (x - 1)));
}
void printString(int n) {
  int arr[10000];
  int i = 0;

  // Step 1: Converting to number assuming
  // 0 in number system
  while (n) {
    arr[i] = n % 26;
    n = n / 26;
    i++;
  }

  // Step 2: Getting rid of 0, as 0 is
  // not part of number system
  for (int j = 0; j < i - 1; j++) {
    if (arr[j] <= 0) {
      arr[j] += 26;
      arr[j + 1] = arr[j + 1] - 1;
    }
  }

  for (int j = i; j >= 0; j--) {
    if (arr[j] > 0)
      cout << char('a' + arr[j] - 1);
  }

  cout << endl;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  printString(n);
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n)                                                            \\
  for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
// const double PI = acos(-1);
const int mod = 1000000007;
int cnt = 0;

void show_vect(vector<bool> v) {
  tr(it, v) { cout << *it << " "; }
  cout << endl;
}
bool isPowerOfTwo(int x) {
  /* First x in the below expression is for the case when x is 0 */
  return x && (!(x & (x - 1)));
}
bool isPrime(int n) {
  // Corner cases
  if (n <= 1)
    return false;
  if (n <= 3)
    return true;

  // This is checked so that we can skip
  // middle five numbers in below loop
  if (n % 2 == 0 || n % 3 == 0)
    return false;

  for (int i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0)
      return false;

  return true;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int cpy = n;
  vi rep;
  while (n) {
    rep.pb(n % 26);
    n /= 26;
  }
  for (int i = 0; i < rep.size() - 2; i++) {
    if (rep[i] <= 0) {
      rep[i] += 26;
      rep[i + 1]--;
    }
  }
  string ans = "";
  for (int i = 0; i < rep.size(); i++) {
    if (rep[i] > 0)
      ans += 'a' + rep[i] - 1;
  }
  reverse(all(ans));
  cout << ans << endl;
}