#K5551. Maximum Mood Score

    ID: 29991 Type: Default 1000ms 256MiB

Maximum Mood Score

Maximum Mood Score

In this problem, you are given TT test cases. For each test case, you are provided with an integer NN representing the length of a sequence and a string of length NN consisting solely of the characters '+' and '-'. The mood score starts at 0 and is updated as you traverse the sequence: you add 1 for a '+' and subtract 1 for a '-'. Your task is to determine the maximum mood score achieved at any point during the sequence processing. Formally, define the mood score as follows:

M0=0M_0 = 0 $$M_i = M_{i-1} + \begin{cases} +1 & \text{if } s_i = '+' \\ -1 & \text{if } s_i = '-' \end{cases} $$

You need to output the maximum value among M0,M1,,MNM_0, M_1, \ldots, M_N for each test case.

inputFormat

The input is read from standard input (stdin) and is in the following format:

  • The first line contains a single integer TT, the number of test cases.
  • For each test case, there are two lines:
    • The first line contains an integer NN, the length of the sequence.
    • The second line contains a string of length NN consisting solely of the characters '+' and '-'.

outputFormat

For each test case, output a single integer on a new line representing the maximum mood score achieved during the sequence.## sample

2
5
++-+-
6
+-+++-
2

3

</p>