Advertisement
jakaria_hossain

codeforces - move brackets

Jun 28th, 2020
1,839
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. #define fast()(ios_base::sync_with_stdio(0),cin.tie(NULL));
  6. #define pi pair<int , int>
  7. #define mp make_pair
  8. #define f first
  9. #define s second
  10.  
  11. int main()
  12. {
  13.     fast();
  14.     ll t;
  15.     cin>>t;
  16.     while(t--)
  17.     {
  18.         ll n,cnt=0,c=0,mx=0;
  19.         cin>>n;
  20.         string s;
  21.         cin>>s;
  22.         ll i=0,j=n/2;
  23.         while(i<j)
  24.         {
  25.             if(s[i]=='(')c++;
  26.             else
  27.             {
  28.                 if(c>0)
  29.                 {
  30.                     c--;
  31.                     //if(cnt>0)cnt--;
  32.                 }
  33.                 else cnt++;
  34.             }
  35.             i++;
  36.  
  37.         }
  38.         c=0;
  39.         n--;
  40.         while(n>=j)
  41.         {
  42.             if(s[n]==')')c++;
  43.             else
  44.             {
  45.                 if(c>0)
  46.                 {
  47.                     c--;
  48.                 }
  49.                 else mx++;
  50.             }
  51.     n--;
  52.         }
  53.         cout<<max(cnt,mx)<<endl;
  54.     }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement