結果

問題 No.3017 交互浴
ユーザー まぬお
提出日時 2025-01-25 14:28:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 228 ms / 2,000 ms
コード長 982 bytes
コンパイル時間 236 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 104,960 KB
最終ジャッジ日時 2025-01-25 23:22:02
合計ジャッジ時間 16,153 ms
ジャッジサーバーID
(参考情報)
judge10 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque, defaultdict
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations
from heapq import heappop, heappush
import math
_int = lambda x: int(x)-1
MOD = 998244353
INF = 1<<60
Yes, No = "Yes", "No"

N = int(input())
H = list(map(int, input().split()))

q = []
ans = 0
for i in range(N):
    h = H[i]
    if i%2 == 0:
        while q:
            l, r = q.pop()
            if r <= h:
                ans -= r-l
            elif l > h:
                q.append((l, r))
                break
            else:
                h = r
                ans -= r-l
                break
        q.append((0, h))
        ans += h
    else:
        while q:
            l, r = q.pop()
            if l > h:
                q.append((l, r))
                break
            elif r <= h:
                ans -= r-l
            else:
                q.append((h, r))
                ans -= h-l
                break
    print(ans)
0