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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  multiset<pair<int, int>> pos, neg;
  rep(i, n) {
    int f = 0, v = 0;
    rep(j, s[i].length()) {
      if (s[i][j] == '(')
        f++;
      else
        f--;
      chmin(v, f);
    }
    if (f >= 0)
      pos.insert({-v, f});
    else
      neg.insert({-(v - f), -f});
  }
  int f = 0;
  for (auto it = pos.begin(); it != pos.end(); it++) {
    pair<int, int> p = *it;
    if (f < p.first) {
      cout << "No\\n";
      return 0;
    } else
      f += p.second;
  }
  int b = 0;
  for (auto it = neg.begin(); it != neg.end(); it++) {
    pair<int, int> p = *it;
    if (b < p.first) {
      cout << "No\\n";
      return 0;
    } else
      b += p.second;
  }
  cout << (f == b ? "Yes" : "No") << '\\n';

  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
// const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

struct Info {
  int a, b;

  Info(int a = 0, int b = 0) : a(a), b(b) {}

  bool operator<(const Info &i) const {
    if (b != i.b)
      return b < i.b;
    else
      return a > i.a;
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  int n;
  cin >> n;
  vector<string> s(n);
  rep(i, n) cin >> s[i];

  vector<Info> p(n);
  int suml = 0, sumr = 0;
  rep(i, n) {
    int l = 0, r = 0;
    rep(j, s[i].length()) {
      if (s[i][j] == '(') {
        l++;
      } else {
        r++;
        chmax(p[i].b, r - l);
      }
    }
    p[i].a = l - r;
    suml += l;
    sumr += r;
  }
  if (suml != sumr) {
    cout << "No" << '\\n';
    return 0;
  }
  sort(p.begin(), p.end());
  int res = 0, idx = 0;
  priority_queue<int> pq;
  rep(i, n) {
    while (idx < n && p[idx].b <= res) {
      pq.push(p[idx].a);
      idx++;
    }
    if (idx == n) {
      cout << "Yes" << '\\n';
      return 0;
    }
    if (pq.top() <= 0) {
      cout << "No" << '\\n';
      return 0;
    }
    res += pq.top();
    pq.pop();
  }
  cout << "Yes" << '\\n';

  return 0;
}