結果

問題 No.3017 交互浴
ユーザー noriaoki
提出日時 2025-02-02 21:13:57
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 444 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 107,392 KB
最終ジャッジ日時 2025-02-02 21:14:19
合計ジャッジ時間 19,008 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
h = list(map(int, input().split()))

q = []
ans = 0
for i in range(n):
    while q and q[-1][0] <= h[i]:
        r, l = q.pop()
        ans -= r - l
    if i%2:
        if q:
            ans -= max(0, h[i] - q[-1][1])
            q[-1][1] = max(h[i], q[-1][1])
    else:
        if q:
            q.append([min(q[-1][1], h[i]), 0])
        else:
            q.append([h[i], 0])
        ans += q[-1][0] - q[-1][1]
    print(ans)
0