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

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define MOD 998244353
typedef long long ll;
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<pair<int, int>> plus;
  vector<pair<int, int>> minus;
  rep(i, n) {
    string t;
    cin >> t;
    int minimum = 0, count = 0;
    rep(j, t.length()) {
      if (t[j] == '(')
        count++;
      else
        count--;
      minimum = min(minimum, count);
    }
    if (count > 0) {
      pair<int, int> ttt;
      ttt.first = minimum;
      ttt.second = count;
      plus.pb(ttt);
    } else {
      int minimum = 0, count = 0;
      for (int j = t.length() - 1; j >= 0; j--) {
        if (t[j] == ')')
          count++;
        else
          count--;
        minimum = min(minimum, count);
      }
      pair<int, int> ttt;
      ttt.first = minimum;
      ttt.second = count;
      minus.pb(ttt);
    }
  }
  sort(plus.begin(), plus.end());
  sort(minus.begin(), minus.end());

  ll countplus = 0, countminus = 0;
  for (int i = plus.size() - 1; i >= 0; i--) {
    if (countplus < (-plus[i].first)) {
      No;
      return 0;
    } else {
      countplus += plus[i].second;
    }
  }
  for (int i = minus.size() - 1; i >= 0; i--) {
    if (countminus < (-minus[i].first)) {
      No;
      return 0;
    } else {
      countminus += minus[i].second;
    }
  }
  if (countplus == countminus)
    Yes;
  else
    No;
  return 0;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define pb push_back
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define MOD 998244353
typedef long long ll;
using namespace std;
vector<ll> fac(300001);
vector<ll> ifac(300001);
ll mpow(ll x, ll n) {
  ll ans = 1;
  while (n != 0) {
    if (n & 1)
      ans = ans * x % MOD;
    x = x * x % MOD;
    n = n >> 1;
  }
  return ans;
}
ll comb(ll a, ll b) {
  if (a == 0 && b == 0)
    return 1;
  if (a < b || a < 0)
    return 0;
  ll tmp = ifac[a - b] * ifac[b] % MOD;
  return tmp * fac[a] % MOD;
}

int main() {
  int n;
  vector<pair<int, int>> num(n);
  cin >> n;
  rep(i, n) {
    string t;
    cin >> t;
    int minimum = INF, count = 0;
    rep(j, t.length()) {
      if (t[j] == '(')
        count++;
      else
        count--;
      minimum = min(minimum, count);
    }
    num[i].first = minimum;
    num[i].second = count;
  }
  sort(num.begin(), num.end());

  ll count = 0;
  int t = n - 1;
  while (t >= 0) {
    if (t = n - 1 && num[t].first < 0) {
      No;
      return 0;
    }
    if (count >= (-num[t].first)) {
      count += num[t].second;
    } else {
      No;
      return 0;
    }
    t--;
  }
  Yes;
  return 0;
}