結果

問題 No.3017 交互浴
コンテスト
ユーザー Facade
提出日時 2025-01-25 15:55:11
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 638 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 82,276 KB
実行使用メモリ 107,816 KB
最終ジャッジ日時 2025-01-25 23:49:27
合計ジャッジ時間 13,068 ms
ジャッジサーバーID
(参考情報)
judge13 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 9 WA * 46
権限があれば一括ダウンロードができます

ソースコード

diff #

n=int(input())
h=list(map(int,input().split()))
stack=[]
green=0
blue=0
for i in range(n):
    while len(stack)>0 and stack[-1][-1]<h[i]:
        a,b=stack.pop()
        if a==1:
            blue-=b
        else:
            green-=b
    if len(stack)>0:
        if stack[-1][-1]>h[i] and stack[-1][0] ==(i+1)%2:
            pass
        else:
            stack.append(((i+1)%2,h[i]))
            if (i+1)%2==1:
                blue+=h[i]
            else:
                green+=h[i]
    else:
        stack.append(((i+1)%2,h[i]))
        if (i+1)%2==1:
            blue+=h[i]
        else:
            green+=h[i]
    print(blue-green)
0