A. A pile of stones
6752 단어 codeforces
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.
Input The first line contains one positive integer n — the number of operations, that have been made by Vasya (1≤n≤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, si is equal to “-” (without quotes), if added, si is equal to “+” (without quotes).
Output Print one integer — the minimal possible number of stones that can be in the pile after these n operations.
Examples inputCopy 3
outputCopy 0 inputCopy 4++++ outputCopy 4 inputCopy 2 -+ outputCopy 1 inputCopy 5 +±++ outputCopy 3 Note 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.
제목: 플러스와 마이너스의 수량을 보면 0이 되면 빼지 않는다
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define dd double
using namespace std;
int main() {
ll n;
cin >> n;
string s;
cin >> s;
ll count = 0;
for (ll i = 0; i < s.size(); i++) {
if (s[i] == '+') {
count++;
}
else {
count--;
if (count < 0) {
count = 0;
}
}
}
cout << count << endl;
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Codeforces Round #715 Div. 2C The Sports Festival: 구간 DP전형구간 DP의 초전형. 이하, 0-indexed. 입력을 정렬하여 어디서나 시작하고 최적으로 좌우로 계속 유지하면 좋다는 것을 알 수 있습니다. {2000})$의 주문이 된다. 우선, 입력을 소트하여 n개의 요소를 $...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.