Problem p03089 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define vllin(x, n)                                                            \
  vll(x)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n)                                                        \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n)                                                           \
  vpl4(x)((n), mp(0, 0));                                                      \
  FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))

ll MOD = 1000000007;

signed main() {
  llin(n);
  vllin(b, n);
  ll l = 0;
  vll c(n, 0);
  rFOR(i, 0, n - 1) {
    rFOR(j, 0, i) {
      if (b[j] == j + 1) {
        l = 1;
        b.erase(b.be + j);
        c[i] = j + 1;
        break;
      }
    }
    if (l == 0) {
      return (-1);
    }
    l = 0;
  }
  FOR(i, 0, n - 1) { sal(c[i]); }
}

Fixed submission:
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll, ll>;
using str = string;
using vpl4 = vector<pair<ll, ll>>;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back
#define mp make_pair

#define llin(x)                                                                \
  ll(x);                                                                       \
  cin >> (x);
#define stin(x)                                                                \
  str(x);                                                                      \
  cin >> (x);
#define vllin(x, n)                                                            \
  vll(x)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (x)[i]; }
#define vllin2(a, b, n)                                                        \
  vll(a)(n);                                                                   \
  vll(b)(n);                                                                   \
  FOR(i, 0, n - 1) { cin >> (a)[i] >> b[i]; }
#define vpl4in(x, n)                                                           \
  vpl4(x)((n), mp(0, 0));                                                      \
  FOR(i, 0, n - 1) { cin >> x[i].fi >> x[i].se; }
#define FOR(i, a, b) for (ll i = a; i <= b; i++)
#define rFOR(i, b, a) for (ll i = a; i >= b; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout << (x);
#define sal(x) cout << (x) << endl;
#define says(x) cout << (x) << (' ');
#define sas cout << (' ');
#define sayR(x) cout << fixed << setprecision(10) << (x);
#define salR(x) cout << fixed << setprecision(10) << (x) << endl;
#define yn(a) cout << ((a) ? "yes" : "no") << endl;
#define Yn(a) cout << ((a) ? "Yes" : "No") << endl;
#define YN(a) cout << ((a) ? "YES" : "NO") << endl;
#define Imp(a) cout << ((a) ? "Possible" : "Impossible") << endl;
#define IMP(a) cout << ((a) ? "POSSIBLE" : "IMPOSSIBLE") << endl;
#define pow(a, b) ll(pow(a, b))

ll MOD = 1000000007;

signed main() {
  llin(n);
  vllin(b, n);
  ll l = 0;
  vll c(n, 0);
  rFOR(i, 0, n - 1) {
    rFOR(j, 0, i) {
      if (b[j] == j + 1) {
        l = 1;
        b.erase(b.be + j);
        c[i] = j + 1;
        break;
      }
    }
    if (l == 0) {
      sal(-1);
      return 0;
    }
    l = 0;
  }
  FOR(i, 0, n - 1) { sal(c[i]); }
}