結果

問題 No.3017 交互浴
ユーザー あじゃじゃ
提出日時 2025-01-09 15:07:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 272 ms / 2,000 ms
コード長 363 bytes
コンパイル時間 306 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 107,008 KB
最終ジャッジ日時 2025-01-25 21:58:10
合計ジャッジ時間 8,314 ms
ジャッジサーバーID
(参考情報)
judge1 / judge10
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
h=list(map(int,input().split()))
stack=[1<<60]
now=0
for i in range(n):
    hi=h[i]
    while stack[-1]<=hi:
        c=stack.pop()
        if len(stack)%2==0:
            now+=c
        else:
            now-=c
    if (len(stack)-i)%2==1:
        stack.append(hi)
        if i%2:
            now-=hi
        else:
            now+=hi
    print(now)
0