Help us understand the problem. What is going on with this article?

Codeforces Round #559 A. A pile of stones

題意

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

アプローチ

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

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)

https://codeforces.com/contest/1159/submission/71169628

recuraki
AtCoder, Codeforces (技術士/CCIE/CISSP/CISM/CISA/一陸技/線路/伝送)
http://www.hogetan.net/note/memo/_resume.html
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした