A12644 | A pile of stones
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Vasya has a pile, that consists of some number of stones. $n$ times he either took one stone from the pile or added one stone to the pile. The pile was non-empty before each operation of taking one stone from the pile.
You are given $n$ operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.
You are given $n$ operations which Vasya has made. Find the minimal possible number of stones that can be in the pile after making these operations.
输入格式
The first line contains one positive integer $n$ — the number of operations, that have been made by Vasya ( $1 \leq n \leq 100$ ).
The next line contains the string $s$ , consisting of $n$ symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on $i$ -th operation, $s_i$ is equal to "-" (without quotes), if added, $s_i$ is equal to "+" (without quotes).
The next line contains the string $s$ , consisting of $n$ symbols, equal to "-" (without quotes) or "+" (without quotes). If Vasya took the stone on $i$ -th operation, $s_i$ is equal to "-" (without quotes), if added, $s_i$ is equal to "+" (without quotes).
输出格式
Print one integer — the minimal possible number of stones that can be in the pile after these $n$ operations.
输入输出样例
输入 #1
3 ---
输出 #1
0
输入 #2
4 ++++
输出 #2
4
输入 #3
2 -+
输出 #3
1
输入 #4
5 ++-++
输出 #4
3
In the first test, if Vasya had $3$ stones in the pile at the beginning, after making operations the number of stones will be equal to $0$ . It is impossible to have less number of piles, so the answer is $0$ . Please notice, that the number of stones at the beginning can't be less, than $3$ , because in this case, Vasya won't be able to take a stone on some operation (the pile will be empty).
In the second test, if Vasya had $0$ stones in the pile at the beginning, after making operations the number of stones will be equal to $4$ . It is impossible to have less number of piles because after making $4$ operations the number of stones in the pile increases on $4$ stones. So, the answer is $4$ .
In the third test, if Vasya had $1$ stone in the pile at the beginning, after making operations the number of stones will be equal to $1$ . It can be proved, that it is impossible to have less number of stones after making the operations.
In the fourth test, if Vasya had $0$ stones in the pile at the beginning, after making operations the number of stones will be equal to $3$ .
In the second test, if Vasya had $0$ stones in the pile at the beginning, after making operations the number of stones will be equal to $4$ . It is impossible to have less number of piles because after making $4$ operations the number of stones in the pile increases on $4$ stones. So, the answer is $4$ .
In the third test, if Vasya had $1$ stone in the pile at the beginning, after making operations the number of stones will be equal to $1$ . It can be proved, that it is impossible to have less number of stones after making the operations.
In the fourth test, if Vasya had $0$ stones in the pile at the beginning, after making operations the number of stones will be equal to $3$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted