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

#include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define printV(v)                                                              \\
  for (auto &&x : v) {                                                         \\
    cout << x << " ";                                                          \\
  }                                                                            \\
  cout << endl
#define printVV(vv)                                                            \\
  for (auto &&v : vv) {                                                        \\
    for (auto &&x : v) {                                                       \\
      cout << x << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp)                                                            \\
  for (auto &&p : vp)                                                          \\
    printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
template <typename T> using Graph = vector<vector<T>>;

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  cin >> n;
  vi c(3);
  rep(i, n) {
    int a;
    cin >> a;
    c[a % 3]++;
  }

  int ans = 1;
  if (c[1] > 0) {
    // 1??????????????¨???
    int c1 = c[1], c2 = c[2];
    int t = c[0] + 1;
    c1--;
    int x = min(c1, c2);
    t += 2 * x;
    c1 -= x;
    c2 -= x;
    t += max(min(c1, 2), min(c2, 1));
    ans = max(ans, t);
  }
  if (c[2] > 0) {
    // 2??????????????¨???
    int c1 = c[1], c2 = c[2];
    int t = c[0] + 1;
    c2--;
    int x = min(c1, c2);
    t += 2 * x;
    c1 -= x;
    c2 -= x;
    t += max(min(c2, 2), min(c1, 1));
    ans = max(ans, t);
  }

  cout << ans << endl;
}

Error: 0
1 0 5
1 0 5
2 0 5
1 1 4
3 0 3
5 0 3


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
// #define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define printV(v)                                                              \\
  for (auto &&x : v) {                                                         \\
    cout << x << " ";                                                          \\
  }                                                                            \\
  cout << endl
#define printVV(vv)                                                            \\
  for (auto &&v : vv) {                                                        \\
    for (auto &&x : v) {                                                       \\
      cout << x << " ";                                                        \\
    }                                                                          \\
    cout << endl;                                                              \\
  }
#define printP(p) cout << p.first << " " << p.second << endl
#define printVP(vp)                                                            \\
  for (auto &&p : vp)                                                          \\
    printP(p);

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<Pii> vp;
const int inf = 1e9;
const int mod = 1e9 + 7;
template <typename T> using Graph = vector<vector<T>>;

signed main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  int n;
  cin >> n;
  vi c(3);
  rep(i, n) {
    int a;
    cin >> a;
    c[a % 3]++;
  }

  int ans = 1;
  if (c[1] > 0) {
    // 1??????????????¨???
    int c1 = c[1], c2 = c[2];
    int t = c[0] + 1;
    c1--;
    cerr << t << " " << c1 << " " << c2 << endl;
    int x = min(c1, c2);
    t += 2 * x;
    c1 -= x;
    c2 -= x;
    cerr << t << " " << c1 << " " << c2 << endl;

    t += max(min(c1, 2), min(c2, 1));
    cerr << t << " " << c1 << " " << c2 << endl;

    ans = max(ans, t);
  }
  if (c[2] > 0) {
    // 2??????????????¨???
    int c1 = c[1], c2 = c[2];
    int t = c[0] + 1;
    c2--;
    cerr << t << " " << c1 << " " << c2 << endl;

    int x = min(c1, c2);
    t += 2 * x;
    c1 -= x;
    c2 -= x;
    cerr << t << " " << c1 << " " << c2 << endl;

    t += max(min(c2, 2), min(c1, 1));
    cerr << t << " " << c1 << " " << c2 << endl;

    ans = max(ans, t);
  }

  cout << ans << endl;
}