#K1446. Balanced Parentheses Check
Balanced Parentheses Check
Balanced Parentheses Check
This problem requires you to determine whether a string of round brackets is balanced. A string is considered balanced if every opening bracket has a corresponding closing bracket in the correct order. In formal terms, let the value of each character be defined as:
\( val('(') = 1 \) and \( val(')') = -1 \). For a string \( S \) of length \( n \), compute the cumulative sum \( balance = \sum_{i=1}^{n} val(S[i]) \). The string is balanced if and only if \( balance = 0 \) and the partial sum is non-negative at every position.
The input is provided through standard input (stdin) and the output must be written to standard output (stdout).
inputFormat
The input consists of a single line containing a string composed solely of the characters '(' and ')'.
outputFormat
Output a single line containing "YES" if the string is balanced, otherwise output "NO".
## sample()
YES