0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

paizaラーニング「加算された数列の最小値 Python3編」

Posted at

私の解答

n = int(input())
a = (int(x) for x in input().split())
s = []
i = 1
for ele in a:
    s.append(ele + i)
    i = i + 1
print(min(s))

解答例

N = int(input())
a = list(map(int, input().split()))

ans = 10000
for i in range(N):
    ans = min(ans, a[i] + (i + 1))

print(ans)
  • 最小値を保持する変数の初期値は 10000 としていますが、例えば a_i が全て 100 だった場合、その最小値は 101 となるので、もし初期値を 101 より小さくしてしまうと、その場合に対応できません。101 以上でその変数に収まる範囲なら、どのような値でも構いません
0
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?