結果

問題 No.2304 Distinct Elements
ユーザー 👑 rin204rin204
提出日時 2024-03-16 15:41:06
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,340 bytes
コンパイル時間 440 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 118,044 KB
最終ジャッジ日時 2024-03-16 15:41:25
合計ジャッジ時間 18,455 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,460 KB
testcase_01 AC 38 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 443 ms
116,572 KB
testcase_10 AC 468 ms
116,572 KB
testcase_11 AC 442 ms
117,652 KB
testcase_12 AC 441 ms
117,652 KB
testcase_13 AC 469 ms
118,044 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 51 ms
63,400 KB
testcase_18 AC 54 ms
63,528 KB
testcase_19 AC 38 ms
53,460 KB
testcase_20 AC 38 ms
53,460 KB
testcase_21 AC 39 ms
53,460 KB
testcase_22 AC 38 ms
53,460 KB
testcase_23 AC 43 ms
53,460 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 328 ms
100,348 KB
testcase_30 AC 121 ms
76,944 KB
testcase_31 AC 266 ms
95,420 KB
testcase_32 AC 371 ms
102,064 KB
testcase_33 AC 126 ms
77,180 KB
testcase_34 AC 402 ms
101,520 KB
testcase_35 AC 411 ms
103,764 KB
testcase_36 AC 125 ms
77,012 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 AC 371 ms
116,540 KB
testcase_44 AC 343 ms
98,688 KB
testcase_45 AC 311 ms
94,488 KB
testcase_46 AC 259 ms
90,188 KB
testcase_47 AC 59 ms
68,052 KB
testcase_48 WA -
testcase_49 WA -
testcase_50 AC 378 ms
107,844 KB
testcase_51 AC 376 ms
107,460 KB
testcase_52 WA -
testcase_53 AC 385 ms
107,848 KB
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 AC 436 ms
107,660 KB
testcase_58 AC 423 ms
107,236 KB
testcase_59 WA -
testcase_60 AC 39 ms
53,460 KB
testcase_61 AC 38 ms
53,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from heapq import *


class SlopeTrick:
    def __init__(self):
        self.minf = 0
        self.inf = 1 << 60
        self.R = [self.inf]
        self.L = [self.inf]
        self.addr = 0
        self.addl = 0

    @property
    def min(self):
        return self.minf

    def get_min(self):
        return (self.minf, -self.L[0] + self.addl, self.R[0] + self.addr)

    # add f(x) = a
    def add(self, a):
        self.minf += a

    # add f(x) = max(0, x - a)
    def add_x_a(self, a):
        self.minf += max(0, -self.L[0] + self.addl - a)
        heappush(self.L, self.addl - a)
        heappush(self.R, -heappop(self.L) + self.addl - self.addr)

    # add f(x) = max(0, a - x)
    def add_a_x(self, a):
        self.minf += max(0, a - self.R[0] - self.addr)
        heappush(self.R, a - self.addr)
        heappush(self.L, -heappop(self.R) - self.addr + self.addl)

    # add f(x) = abs(x - a)
    def add_abs(self, a):
        self.add_a_x(a)
        self.add_x_a(a)

    def add_l(self, x):
        assert x <= 0
        self.addl += x

    def add_r(self, x):
        assert x >= 0
        self.addr += x


n = int(input())
A = list(map(int, input().split()))
A.sort()
for i in range(n):
    A[i] -= i

st = SlopeTrick()
for a in A:
    st.add_abs(a)
    while len(st.R) > 1:
        st.add_a_x(-heappop(st.R))

print(st.min)
0