結果

問題 No.2304 Distinct Elements
コンテスト
ユーザー titia
提出日時 2023-05-16 07:55:52
言語 Python3
(3.14.3 + numpy 2.4.4 + scipy 1.17.1)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 538 ms / 3,000 ms
コード長 380 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 544 ms
コンパイル使用メモリ 20,712 KB
実行使用メモリ 36,280 KB
最終ジャッジ日時 2026-05-25 04:06:08
合計ジャッジ時間 25,203 ms
ジャッジサーバーID
(参考情報)
judge3_1 / judge1_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