結果

問題 No.1077 Noelちゃんと星々4
コンテスト
ユーザー nephrologist
提出日時 2020-06-12 21:56:46
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
WA  
実行時間 -
コード長 498 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,234 ms
コンパイル使用メモリ 20,696 KB
実行使用メモリ 15,488 KB
最終ジャッジ日時 2026-03-10 03:12:00
合計ジャッジ時間 4,126 ms
ジャッジサーバーID
(参考情報)
judge1_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 1 WA * 19
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

n = int(input())
A = list(map(int, input().split()))
pre = A[0]
cnt = 0
kaisa = [0] * (n - 1)
for i in range(n - 1):
    kaisa[i] = A[i + 1] - A[i]
for i in range(n - 1):
    if kaisa[i] >= 0:
        continue
    if i >= 1:
        if kaisa[i - 1] > 0:
            cnt += min(kaisa[i - 1], -kaisa[i])
            kaisa[i] = min(kaisa[i] + kaisa[i - 1], 0)
            if kaisa[i] >= 0:
                continue
    cnt += -kaisa[i]
    if i != n - 2:
        kaisa[i + 1] += kaisa[i]


print(cnt)
0