Official

A - 混雑する階段 / Steep Stairs Editorial by sounansya


AtCoder をはじめたばかりで何をしたらよいか分からない方は、まずは practice contest の問題 A「Welcome to AtCoder」を解いてみてください。基本的な入出力の方法が載っています。
また、プログラミングコンテストの問題に慣れていない方は、AtCoder Beginners Selection の問題をいくつか解いてみることをおすすめします。


for 文を用いて問題文の通りに消耗する体力の合計を計算すれば良いです。

実装例(Python3)

n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    if a[i] > a[i - 1]:
        ans += 2 * a[i]
    else:
        ans += a[i]
print(ans)

posted:
last update: