結果

問題 No.2304 Distinct Elements
コンテスト
ユーザー titia
提出日時 2023-05-16 07:55:52
言語 Python3
(3.15.0 + numpy 2.5.4 + scipy 1.18.1 + ACL)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 445 ms / 3,000 ms
+ 451µs
コード長 380 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 54 ms
コンパイル使用メモリ 15,232 KB
実行使用メモリ 32,956 KB
最終ジャッジ日時 2026-10-03 09:57:59
合計ジャッジ時間 18,376 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 58
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

import sys
input = sys.stdin.readline

from heapq import heappop,heappush

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

A.sort()
for i in range(N):
    A[i]-=i

L=[10**18]
R=[10**18]

MIN=0

for a in A:
    heappush(R,a)
    x=heappop(R)
    MIN+=abs(x-a)
    heappush(L,-x)

    heappush(L,-a)
    x=-heappop(L)
    heappush(R,x)
    MIN+=abs(x-a)

    R=[10**18]

print(MIN)
0