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

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];
  if (a[0] + a[1] + a[2] == 0) {
    cout << "No" << '\\n';
    return 0;
  }
  if (a[0] + a[1] + a[2] == 1) {
    char ans[n];
    for (int i = 0; i < n; ++i) {
      string _s;
      cin >> _s;
      int s[] = {_s[0] - 'A', _s[1] - 'A'};
      if (a[s[0]] == 0 and a[s[1]] == 0) {
        cout << "No" << '\\n';
        return 0;
      }
      if (a[s[0]] == 0)
        ans[i] = s[0] + 'A';
      if (a[s[1]] == 0)
        ans[i] = s[1] + 'A';
      swap(a[s[0]], a[s[1]]);
    }
    cout << "Yes" << '\\n';
    for (int i = 0; i < n; ++i) {
      cout << ans[i] << '\\n';
    }
    return 0;
  }
  int s[n][2];
  char ans[n];
  for (int i = 0; i < n; ++i) {
    string _s;
    cin >> _s;
    s[i][0] = _s[0] - 'A';
    s[i][1] = _s[1] - 'A';
  }
  for (int i = 0; i < n; ++i) {
    if (a[s[i][0]] == 0 and a[s[i][1]] == 0) {
      cout << "No" << '\\n';
      return 0;
    }
    int pl, mi;
    if (a[s[i][0]] == 0) {
      pl = s[i][0];
      mi = s[i][1];
    } else if (a[s[i][1]] == 0) {
      pl = s[i][1];
      mi = s[i][0];
    } else if (i + 1 < n) {
      for (int j = 0; j < 2; ++j) {
        if (s[i][0] == s[i + 1][j]) {
          pl = s[i][0];
          mi = s[i][1];
        }
        if (s[i][1] == s[i + 1][j]) {
          pl = s[i][1];
          mi = s[i][0];
        }
      }
    } else {
      pl = s[i][0];
      mi = s[i][1];
    }
    ans[i] = pl + 'A';
    a[pl]++;
    a[mi]--;
  }
  cout << "Yes" << '\\n';
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << '\\n';
  }
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int n, a[3];
  cin >> n >> a[0] >> a[1] >> a[2];
  if (a[0] + a[1] + a[2] == 0) {
    cout << "No" << '\\n';
    return 0;
  }
  if (a[0] + a[1] + a[2] == 1) {
    char ans[n];
    for (int i = 0; i < n; ++i) {
      string _s;
      cin >> _s;
      int s[] = {_s[0] - 'A', _s[1] - 'A'};
      if (a[s[0]] == 0 and a[s[1]] == 0) {
        cout << "No" << '\\n';
        return 0;
      }
      if (a[s[0]] == 0)
        ans[i] = s[0] + 'A';
      if (a[s[1]] == 0)
        ans[i] = s[1] + 'A';
      swap(a[s[0]], a[s[1]]);
    }
    for (int i = 0; i < n; ++i) {
      cout << ans[i] << '\\n';
    }
    return 0;
  }
  int s[n][2];
  char ans[n];
  for (int i = 0; i < n; ++i) {
    string _s;
    cin >> _s;
    s[i][0] = _s[0] - 'A';
    s[i][1] = _s[1] - 'A';
  }
  for (int i = 0; i < n; ++i) {
    if (a[s[i][0]] == 0 and a[s[i][1]] == 0) {
      cout << "No" << '\\n';
      return 0;
    }
    int pl, mi;
    if (a[s[i][0]] == 0) {
      pl = s[i][0];
      mi = s[i][1];
    } else if (a[s[i][1]] == 0) {
      pl = s[i][1];
      mi = s[i][0];
    } else {
      for (int j = 0; j < 2; ++j) {
        if (s[i][0] == s[i + 1][j]) {
          pl = s[i][0];
          mi = s[i][1];
        }
        if (s[i][1] == s[i + 1][j]) {
          pl = s[i][1];
          mi = s[i][0];
        }
      }
    }
    ans[i] = pl + 'A';
    a[pl]++;
    a[mi]--;
  }
  cout << "Yes" << '\\n';
  for (int i = 0; i < n; ++i) {
    cout << ans[i] << '\\n';
  }
  return 0;
}