Qiita Teams that are logged in
You are not logged in to any team

Community
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What is going on with this article?
@recuraki

# Codeforces Round #559 A. A pile of stones

More than 1 year has passed since last update.

# 題意

• あなたは最初`x`個の石を持っていた
• `+` (石を場からとる)か `-` (石を場に置く)をした
• この間`-`にて手元から石がなくなることはなかった
• 最後に手元にある石の最小数を述べよ

# アプローチ

この数の石を初期値にした上で、再度シミュレーションすればよいです。
※あるいは上記で求めた最後の値にこの足りなくなる数を足しても良いです。(コードはこちらのアプローチ)

``````n = int(input())
s = input()
mi = 0
c = 0
for i in range(n):
if s[i] == "+":
c += 1
else:
c -= 1
mi = min(mi, c)
c -= mi
print(c)
``````

0
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away
AtCoder(水), Codeforces(青), TopCoder(青)をうろうろ (技術士/CCIE/CISSP/CISM/CISA/一陸技/線路/伝送)