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

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (long long i = o; i < n; i++)
#define oneforall                                                              \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define ini(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define inl(...)                                                               \\
  long long __VA_ARGS__;                                                       \\
  in(__VA_ARGS__)
#define ins(...)                                                               \\
  string __VA_ARGS__;                                                          \\
  in(__VA_ARGS__)
const long long INF = 1e18;
void in() {}
template <typename T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void out() { cout << "\\n"; }
template <typename T, class... U> void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long>> vpll;
typedef vector<pair<int, int>> vpii;
int main() {
  oneforall oneforall oneforall oneforall oneforall oneforall oneforall
      oneforall oneforall oneforall oneforall oneforall oneforall oneforall ini(
          n);
  ll total = 0;
  if (n >= 500) {
    int tmp = n / 500;
    n -= tmp * 500;
    total += tmp * 1000;
  }
  if (n >= 5) {
    int tmp1 = n / 5;
    n -= tmp1 * 5;
    total += tmp1 * 5;
  }
  out(total);
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (long long i = o; i < n; i++)
#define oneforall                                                              \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);
#define all(v) (v).begin(), (v).end()
#define ini(...)                                                               \\
  int __VA_ARGS__;                                                             \\
  in(__VA_ARGS__)
#define inl(...)                                                               \\
  long long __VA_ARGS__;                                                       \\
  in(__VA_ARGS__)
#define ins(...)                                                               \\
  string __VA_ARGS__;                                                          \\
  in(__VA_ARGS__)
const long long INF = 1e18;
void in() {}
template <typename T, class... U> void in(T &t, U &...u) {
  cin >> t;
  in(u...);
}
void out() { cout << "\\n"; }
template <typename T, class... U> void out(const T &t, const U &...u) {
  cout << t;
  if (sizeof...(u))
    cout << " ";
  out(u...);
}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long>> vpll;
typedef vector<pair<int, int>> vpii;
int main() {
  oneforall oneforall oneforall oneforall oneforall oneforall oneforall
      oneforall oneforall oneforall oneforall oneforall oneforall oneforall ini(
          n);
  while (n--) {
    inl(x);
    inl(k);
    k *= 2;
    char a[200009];
    FOR(i, 0, x) { a[i] = 'a'; }
    ll tmp;
    FOR(i, 0, 100000) {
      if ((i * (i + 1)) >= k) {
        tmp = i;
        break;
      }
    }
    a[x - 1 - tmp] = 'b';
    k /= 2;
    ll tmp1 = (tmp * (tmp + 1)) / 2;
    a[x - (k - (tmp1 - tmp))] = 'b';
    FOR(i, 0, x) { cout << a[i]; }
    cout << "\\n";
  }
  return 0;
}