Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- int main()
- {
- string s;
- cin >> s;
- int bal = 0, k = 0, ans;
- for(int i = 0; i < s.size(); i++)
- {
- if (s[i] == '(') bal++;
- else bal--;
- if (bal+k < 0)
- {
- ans++;
- k++;
- }
- }
- cout << ans + bal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement