题目描述
Problem Description
Takahashi loves browsing the internet using his browser.
However, he has a habit of opening too many tabs, which often causes his browser to crash.
Takahashi's browser crashes when the number of open tabs exceeds $ L $.
When the browser crashes, it automatically restarts with only $ 1 $ tab open.
Initially, Takahashi's browser has $ 1 $ tab open.
Given the history of Takahashi's actions of "opening a new tab" and "closing a tab", determine how many times Takahashi crashes his browser.
Input Format
The input is given from the standard input in the following format:
$ N $ $ L $ $ S $
- The first line contains an integer $N(1\ ≦\ N\ ≦\ 10^5)$ representing the number of actions Takahashi performed, and an integer $L(1\ ≦\ L\ ≦\ 10^5)$ representing the threshold at which the browser crashes, separated by spaces.
- The second line contains a string $ S $ of $ N $ characters consisting only of
+and-, representing the chronological history of Takahashi's actions. +indicates opening a new tab, and-indicates closing a tab.- It is guaranteed that Takahashi will not close a tab when there is only $ 1 $ tab open.
Output Format
Output an integer on a single line representing the number of times Takahashi crashes his browser. End the output with a newline.
Sample Input and Output
Sample Input #1
6 2
+++-++
Sample Output #1
2
Sample Input #2
20 20
++-+-+++--+++++-++++
Sample Output #2
0
Notes/Hints
Sample Explanation 1
- Initially, the number of tabs is $ 1 $.
- After the first operation, the number of tabs is $ 2 $.
- After the second operation, the number of tabs becomes $ 3 $, which is greater than $ L $, so the browser crashes and the number of tabs resets to $ 1 $.
- After the third operation, the number of tabs is $ 2 $.
- After the fourth operation, the number of tabs is $ 1 $.
- After the fifth operation, the number of tabs is $ 2 $.
- After the sixth operation, the number of tabs becomes $ 3 $, which is greater than $ L $, so the browser crashes and the number of tabs resets to $ 1 $.
Thus, the browser crashes a total of $ 2 $ times.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分