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

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

int main() {
  int N, A, B, C;
  scanf("%d", &N);
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  std::queue<char> queue;
  bool result = true;
  std::vector<std::string> s(N);
  std::vector<std::string> next(N);
  next[N - 1] = "AB";
  for (int i = 0; i < N; i++) {
    std::cin >> s[i];
  }
  std::string cand = s[N - 1];
  for (int i = N - 2; i > 0; i--) {
    next[i] = cand;
    if (s[i - 1] != s[i])
      cand = s[i];
  }
  next[0] = cand;

  /*for (int i=0; i<N; i++){
    std::cout << i << ": " << next[i] << std::endl;
    }*/

  for (int i = 0; i < N; i++) {
    if (s[i] == "AB") {
      if (A == B && next[i] == "BC") {
        B++;
        A--;
        queue.push('B');
      } else if (A == B && next[i] == "AC") {
        A++;
        B--;
        queue.push('A');
      } else if (A > B) {
        A--;
        B++;
        queue.push('B');
      } else {
        A++;
        B--;
        queue.push('A');
      }
      if (A < 0 || B < 0) {
        result = false;
      }
    } else if (s[i] == "BC") {
      if (B == C && next[i] == "AC") {
        C++;
        B--;
        queue.push('C');
      } else if (B == C && next[i] == "AB") {
        B++;
        C--;
        queue.push('B');
      } else if (B > C) {
        B--;
        C++;
        queue.push('C');
      } else {
        B++;
        C--;
        queue.push('B');
      }
      if (B < 0 || C < 0) {
        result = false;
      }
    } else {
      if (A == C && next[i] == "AB") {
        A++;
        C--;
        queue.push('A');
      } else if (A == C && next[i] == "BC") {
        C++;
        A--;
        queue.push('C');
      } else if (C > A) {
        C--;
        A++;
        queue.push('A');
      } else {
        C++;
        A--;
        queue.push('C');
      }
      if (C < 0 || A < 0) {
        result = false;
      }
    }
  }
  if (result) {
    printf("Yes\\n");
    while (queue.size() > 0) {
      char value = queue.front();
      printf("%c\\n", value);
      queue.pop();
    }
  } else {
    printf("No\\n");
  }
  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unordered_map>
#include <vector>

void execution(int x, int y) {}

int main() {
  int N, A, B, C;
  scanf("%d", &N);
  scanf("%d", &A);
  scanf("%d", &B);
  scanf("%d", &C);
  std::string s;
  std::queue<char> queue;
  for (int i = 0; i < N; i++) {
    std::cin >> s;
    if (s == "AB") {
      if (A > B) {
        A--;
        B++;
        queue.push('B');
      } else {
        A++;
        B--;
        queue.push('A');
      }
      if (A < 0 || B < 0) {
        printf("No\\n");
        return -1;
      }
    } else if (s == "BC") {
      if (B > C) {
        B--;
        C++;
        queue.push('C');
      } else {
        B++;
        C--;
        queue.push('B');
      }
      if (B < 0 || C < 0) {
        printf("No\\n");
        return -1;
      }
    } else {
      if (C > A) {
        C--;
        A++;
        queue.push('A');
      } else {
        C++;
        A--;
        queue.push('C');
      }
      if (C < 0 || A < 0) {
        printf("No\\n");
        return -1;
      }
    }
  }
  printf("Yes\\n");
  while (queue.size() > 0) {
    char value = queue.front();
    printf("%c\\n", value);
    queue.pop();
  }
  return 0;
}