Language: C++

#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 1e6 + 5;

struct data
{
	int clos, op, bal;
};

int n;
string s[N];
int bal[N];
data a[N];

void work(int idx, string &s)
{
	stack<char> st;
	for(auto &it:s)
	{
		if(it == '(')
			st.push(it);
		else
		{
			if(st.size() && st.top() == '(')
				st.pop();
			else
				st.push(')');
		}
	}
	map<char, int> m;
	while(st.size())
	{
		m[st.top()]++;
		st.pop();
	}
	a[idx].clos = m[')'];
	a[idx].op = m['('];
	a[idx].bal = m['('] - m[')'];
}

bool comp(data &a, data &b)
{
	if(a.clos != b.clos)
		return a.clos < b.clos;
	return a.bal > b.bal;
}

int32_t main()
{
	IOS;
	cin >> n;
	for(int i = 1; i <= n; i++)
	{
		cin >> s[i];
		work(i, s[i]);
	}
	sort(a + 1, a + n + 1, comp);
	int have = 0;
	priority_queue<pair<int, pair<int, int> > > pq;
	int i = 1, taken = 0;
	while(taken < n)
	{
		while(i <= n)
		{
			if(a[i].clos <= have)
			{
				pq.push({a[i].bal, {a[i].op, a[i].clos}});
				i++;
			}
			else
				break;
		}
		if(pq.size())
		{
			pair<int, pair<int, int> > p = pq.top();
			pq.pop();
			taken++;
			if(p.second.second > have)
			{
				cerr << "Hi";
				cout << "No";
				return 0;
			}
			have += p.first;
		}
		else
		{
			cout << "No";
			return 0;
		}
	}
	if(have != 0)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}

Compiler output:
a.cc:18:1: error: reference to 'data' is ambiguous
   18 | data a[N];
      | ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:8: note:                 'struct data'
   10 | struct data
      |        ^~~~
a.cc: In function 'void work(long long int, std::string&)':
a.cc:41:9: error: 'a' was not declared in this scope
   41 |         a[idx].clos = m[')'];
      |         ^
a.cc: At global scope:
a.cc:46:11: error: reference to 'data' is ambiguous
   46 | bool comp(data &a, data &b)
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:8: note:                 'struct data'
   10 | struct data
      |        ^~~~
a.cc:46:17: error: 'a' was not declared in this scope
   46 | bool comp(data &a, data &b)
      |                 ^
a.cc:46:20: error: reference to 'data' is ambiguous
   46 | bool comp(data &a, data &b)
      |                    ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:10:8: note:                 'struct data'
   10 | struct data
      |        ^~~~
a.cc:46:26: error: 'b' was not declared in this scope
   46 | bool comp(data &a, data &b)
      |                          ^
a.cc:46:27: error: expression list treated as compound expression in initializer [-fpermissive]
   46 | bool comp(data &a, data &b)
      |                           ^
a.cc: In function 'int32_t main()':
a.cc:62:14: error: 'a' was not declared in this scope
   62 |         sort(a + 1, a + n + 1, comp);
      |              ^
a.cc:72:40: error: no matching function for call to 'std::priority_queue<std::pair<long long int, std::pair<long long int, long long int> > >::push(<brace-enclosed initializer list>)'
   72 |                                 pq.push({a[i].bal, {a[i].op, a[i].clos}});
      |                                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/queue:66,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:157:
/usr/include/c++/14/bits/stl_queue.h:736:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<long long int, std::pair<long long int, long long int> >; _Sequence = std::vector<std::pair<long long int, std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, std::pair<long long int, long long int> > > >; _Compare = std::less<std::pair<long long int, std::pair<long long int, long long int> > >; value_type = std::pair<long long int, std::pair<long long int, long long int> >]'
  736 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:736:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const std::priority_queue<std::pair<long long int, std::pair<long long int, long long int> > >::value_type&' {aka 'const std::pair<long long int, std::pair<long long int, long long int> >&'}
  736 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_queue.h:744:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(value_type&&) [with _Tp = std::pair<long long int, std::pair<long long int, long long int> >; _Sequence = std::vector<std::pair<long long int, std::pair<long long int, long long int> >, std::allocator<std::pair<long long int, std::pair<long long int, long long int> > > >; _Compare = std::less<std::pair<long long int, std::pair<long long int, long long int> > >; value_type = std::pair<long long int, std::pair<long long int, long long int> >]'
  744 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/14/bits/stl_queue.h:744:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<long long int, std::pair<long long int, long long int> > >::value_type&&' {aka 'std::pair<long long int, std::pair<long long int, long long int> >&&'}
  744 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~