Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
- #define pi pair<int , int>
- #define mp make_pair
- #define f first
- #define s second
- int main()
- {
- fast();
- ll t;
- cin>>t;
- while(t--)
- {
- ll n,cnt=0,c=0,mx=0;
- cin>>n;
- string s;
- cin>>s;
- ll i=0,j=n/2;
- while(i<j)
- {
- if(s[i]=='(')c++;
- else
- {
- if(c>0)
- {
- c--;
- //if(cnt>0)cnt--;
- }
- else cnt++;
- }
- i++;
- }
- c=0;
- n--;
- while(n>=j)
- {
- if(s[n]==')')c++;
- else
- {
- if(c>0)
- {
- c--;
- }
- else mx++;
- }
- n--;
- }
- cout<<max(cnt,mx)<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement