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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  ll N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> vec(0);
  vector<string> ABC(N);
  rep(i, N) { cin >> ABC[i]; }
  bool possible = true;
  rep(i, N) {
    if (ABC[i] == "AB") {
      if (A == 0 && B == 0) {
        possible = false;
      } else if (i != N - 1 && A == 1 && B == 1) {
        if (ABC[i + 1] == "AC") {
          A++;
          B--;
          vec.push_back("A");
        } else if (ABC[i + 1] == "BC") {
          A--;
          B++;
          vec.push_back("B");
        } else {
          A++;
          B--;
          vec.push_back("A");
        }
      } else if (A >= B) {
        A--;
        B++;
        vec.push_back("B");
      } else {
        A++;
        B--;
        vec.push_back("A");
      }
    } else if (ABC[i] == "AC") {
      if (A == 0 && C == 0) {
        possible = false;
      } else if (i != N - 1 && A == 1 && C == 1) {
        if (ABC[i + 1] == "AB") {
          A++;
          C--;
          vec.push_back("A");
        } else if (ABC[i + 1] == "BC") {
          A--;
          C++;
          vec.push_back("C");
        } else {
          A++;
          C--;
          vec.push_back("A");
        }
      } else if (A >= C) {
        A--;
        C++;
        vec.push_back("C");
      } else {
        A++;
        C--;
        vec.push_back("A");
      }
    } else if (ABC[i] == "BC") {
      if (B == 0 && C == 0) {
        possible = false;
      } else if (i != N - 1 && B == 1 && C == 1) {
        if (ABC[i + 1] == "AB") {
          B++;
          C--;
          vec.push_back("B");
        } else if (ABC[i + 1] == "AC") {
          B--;
          C++;
          vec.push_back("C");
        } else {
          B++;
          C--;
          vec.push_back("B");
        }
      } else if (B >= C) {
        B--;
        C++;
        vec.push_back("C");
      } else {
        B++;
        C--;
        vec.push_back("B");
      }
    }
  }
  if (!possible) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    rep(i, N) { cout << vec[i] << endl; }
  }
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(), v.end()
typedef long long ll;

int main() {
  ll N, A, B, C;
  cin >> N >> A >> B >> C;
  vector<string> vec(0);
  vector<string> ABC(N);
  rep(i, N) { cin >> ABC[i]; }
  bool possible = true;
  rep(i, N) {
    if (ABC[i] == "AB") {
      if (A == 0 && B == 0) {
        possible = false;
      } else if (i != N - 1) {
        if (A == 1 && B == 1) {
          if (ABC[i + 1] == "AC") {
            A++;
            B--;
            vec.push_back("A");
          } else if (ABC[i + 1] == "BC") {
            A--;
            B++;
            vec.push_back("B");
          } else {
            A++;
            B--;
            vec.push_back("A");
          }
        }
      } else if (A >= B) {
        A--;
        B++;
        vec.push_back("B");
      } else {
        A++;
        B--;
        vec.push_back("A");
      }
    } else if (ABC[i] == "AC") {
      if (A == 0 && C == 0) {
        possible = false;
      } else if (i != N - 1) {
        if (A == 1 && C == 1) {
          if (ABC[i + 1] == "AB") {
            A++;
            C--;
            vec.push_back("A");
          } else if (ABC[i + 1] == "BC") {
            A--;
            C++;
            vec.push_back("C");
          } else {
            A++;
            C--;
            vec.push_back("A");
          }
        }
      } else if (A >= C) {
        A--;
        C++;
        vec.push_back("C");
      } else {
        A++;
        C--;
        vec.push_back("A");
      }
    } else if (ABC[i] == "BC") {
      if (B == 0 && C == 0) {
        possible = false;
      } else if (i != N - 1) {
        if (B == 1 && C == 1) {
          if (ABC[i + 1] == "AB") {
            B++;
            C--;
            vec.push_back("B");
          } else if (ABC[i + 1] == "AC") {
            B--;
            C++;
            vec.push_back("C");
          } else {
            B++;
            C--;
            vec.push_back("B");
          }
        }
      } else if (B >= C) {
        B--;
        C++;
        vec.push_back("C");
      } else {
        B++;
        C--;
        vec.push_back("B");
      }
    }
  }
  if (!possible) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
    rep(i, N) { cout << vec[i] << endl; }
  }
}