結果

問題 No.2217 Suffix+
ユーザー 👑 KazunKazun
提出日時 2023-02-17 21:26:36
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 283 ms / 2,000 ms
コード長 2,967 bytes
コンパイル時間 310 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 93,168 KB
最終ジャッジ日時 2023-09-26 18:32:47
合計ジャッジ時間 7,878 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
70,964 KB
testcase_01 AC 85 ms
71,216 KB
testcase_02 AC 84 ms
71,344 KB
testcase_03 AC 83 ms
71,204 KB
testcase_04 AC 82 ms
71,156 KB
testcase_05 AC 83 ms
70,952 KB
testcase_06 AC 85 ms
71,152 KB
testcase_07 AC 82 ms
71,116 KB
testcase_08 AC 81 ms
70,940 KB
testcase_09 AC 84 ms
71,212 KB
testcase_10 AC 82 ms
71,292 KB
testcase_11 AC 81 ms
71,332 KB
testcase_12 AC 83 ms
71,112 KB
testcase_13 AC 82 ms
71,248 KB
testcase_14 AC 117 ms
78,576 KB
testcase_15 AC 124 ms
78,748 KB
testcase_16 AC 153 ms
83,744 KB
testcase_17 AC 138 ms
80,768 KB
testcase_18 AC 127 ms
79,848 KB
testcase_19 AC 220 ms
88,296 KB
testcase_20 AC 200 ms
86,600 KB
testcase_21 AC 105 ms
76,744 KB
testcase_22 AC 216 ms
87,964 KB
testcase_23 AC 190 ms
83,936 KB
testcase_24 AC 217 ms
92,924 KB
testcase_25 AC 221 ms
92,932 KB
testcase_26 AC 219 ms
92,928 KB
testcase_27 AC 216 ms
93,060 KB
testcase_28 AC 215 ms
93,080 KB
testcase_29 AC 256 ms
93,168 KB
testcase_30 AC 264 ms
93,072 KB
testcase_31 AC 263 ms
93,032 KB
testcase_32 AC 262 ms
92,932 KB
testcase_33 AC 263 ms
92,924 KB
testcase_34 AC 214 ms
90,420 KB
testcase_35 AC 81 ms
71,284 KB
testcase_36 AC 283 ms
93,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Decrease_Search_Integer(L, R, cond, default=None):
    """ 条件式が単調減少であるとき, 整数上で二部探索を行う.

    L: 解の下限
    R: 解の上限
    cond: 条件 (1変数関数, 広義単調減少 を満たす)
    default: R で条件を満たさないときの返り値
    """

    if not(cond(L)):
        return default

    if cond(R):
        return R

    L-=1
    while R-L>1:
        C=L+(R-L)//2
        if cond(C):
            L=C
        else:
            R=C
    return L

#==================================================
import heapq

class Double_Heap:
    def __init__(self):
        self.__small=[]
        self.__large=[]
        self.__dict={}
        self.__length=0
        self.__sum=0

    def __bool__(self):
        return bool(self.__length)

    def __len__(self):
        return self.__length

    def __contains__(self, x):
        return self.is_exist(x)

    def push(self, x):
        self.__length+=1
        self.__sum+=x

        heapq.heappush(self.__small, x)
        heapq.heappush(self.__large, -x)

        if x in self.__dict:
            self.__dict[x]+=1
        else:
            self.__dict[x]=1

    def discard(self, x):
        """ x を消す (存在しない場合は何もしない). """

        if x not in self:
            return

        self.__dict[x]-=1
        if self.__dict[x]==0:
            del self.__dict[x]

        self.__length-=1
        self.__sum-=x

        while self.__small and (self.__small[0] not in self):
                heapq.heappop(self.__small)

        while self.__large and (-self.__large[0] not in self):
                heapq.heappop(self.__large)

    def is_exist(self, x):
        """ キューに x が存在するかどうかを判定する. """
        return x in self.__dict

    def get_min(self):
        assert self
        return self.__small[0]

    def pop_min(self):
        assert self
        x=self.get_min()
        self.discard(x)
        return x

    def get_max(self):
        assert self
        return -self.__large[0]

    def pop_max(self):
        assert self
        x=self.get_max()
        self.discard(x)
        return x

    def count(self, x):
        """ x の個数を求める. """

        return self.__dict.get(x,0)

    def sum(self):
        return self.__sum

    def __str__(self):
        return str(self.__dict)

    def __repr__(self):
        return "[Double Heap]: "+str(self)

#==================================================
def solve():
    N,K=map(int,input().split())
    A=[-1]+list(map(int,input().split()))

    def check(X):
        count=0
        added=0
        for i in range(1,N+1):
            delta=max(0, X-(A[i]+added))
            k=(delta+i-1)//i
            count+=k
            added+=i*k
        return count<=K

    return General_Binary_Decrease_Search_Integer(0,10**15,check,-1)
#==================================================
print(solve())
0