結果

問題 No.1077 Noelちゃんと星々4
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-03-16 23:28:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 58 ms / 2,000 ms
コード長 253 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 81,692 KB
実行使用メモリ 65,676 KB
最終ジャッジ日時 2023-10-25 07:05:39
合計ジャッジ時間 2,412 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,316 KB
testcase_01 AC 39 ms
53,316 KB
testcase_02 AC 54 ms
63,592 KB
testcase_03 AC 58 ms
65,676 KB
testcase_04 AC 43 ms
59,016 KB
testcase_05 AC 40 ms
53,316 KB
testcase_06 AC 48 ms
61,524 KB
testcase_07 AC 47 ms
61,144 KB
testcase_08 AC 46 ms
59,096 KB
testcase_09 AC 44 ms
59,016 KB
testcase_10 AC 55 ms
63,596 KB
testcase_11 AC 50 ms
61,164 KB
testcase_12 AC 49 ms
61,164 KB
testcase_13 AC 40 ms
53,316 KB
testcase_14 AC 55 ms
63,596 KB
testcase_15 AC 49 ms
61,148 KB
testcase_16 AC 45 ms
59,096 KB
testcase_17 AC 51 ms
61,296 KB
testcase_18 AC 56 ms
63,612 KB
testcase_19 AC 41 ms
53,316 KB
testcase_20 AC 39 ms
53,316 KB
testcase_21 AC 56 ms
65,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import heappush, heappop

n = int(input())
H = list(map(int,input().split()))
ans = 0

lis = []
for h in H:
    if lis and lis[0] < -h:
        l = -heappop(lis)
        ans += abs(l-h)
        heappush(lis,-h)
    heappush(lis,-h)
print(ans)
0