結果

問題 No.3017 交互浴
コンテスト
ユーザー まぬお
提出日時 2025-01-25 14:28:58
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 157 ms / 2,000 ms
コード長 982 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 187 ms
コンパイル使用メモリ 84,992 KB
実行使用メモリ 113,664 KB
最終ジャッジ日時 2026-06-24 01:08:11
合計ジャッジ時間 12,266 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 55
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

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