結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー tamato
提出日時 2021-11-12 21:35:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 833 bytes
コンパイル時間 155 ms
コンパイル使用メモリ 82,336 KB
実行使用メモリ 537,604 KB
最終ジャッジ日時 2024-11-25 17:21:39
合計ジャッジ時間 73,302 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26 TLE * 12 MLE * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    from heapq import heappush, heappop, heapify
    input = sys.stdin.readline

    N, A, B, X, Y = map(int, input().split())
    H = list(map(int, input().split()))

    ok = sum(H)
    ng = -1
    mid = (ok + ng) // 2
    while ok - ng > 1:
        HH = [max(0, h - mid) for h in H]
        pq = []
        for i, h in enumerate(HH):
            pq.append((-h, i))
        heapify(pq)
        AA = A
        while AA and pq:
            AA -= 1
            h, i = heappop(pq)
            h = -h
            HH[i] = max(0, HH[i] - X)
            if h - X > 0:
                heappush(pq, (-(h - X), i))
        if sum(HH) <= B * Y:
            ok = mid
        else:
            ng = mid
        mid = (ok + ng) // 2
    print(ok)


if __name__ == '__main__':
    main()
0