結果

問題 No.1739 Princess vs. Dragoness (& AoE)
ユーザー Shirotsume
提出日時 2021-10-29 19:07:27
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 2,833 ms / 3,000 ms
コード長 1,001 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,600 KB
最終ジャッジ日時 2024-11-25 11:10:18
合計ジャッジ時間 50,165 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda: sys.stdin.readline().rstrip()
n, a, b, x, y = map(int,input().split())
h = list(map(int,input().split()))
def solve(n, a, b, x, y, h):
    h.sort()
    from collections import deque
    def check(k):
        q1 = deque()
        q2 = deque()
        for i in range(n):
            q1.append(max(h[i] - k, 0))
        for _ in range(a):
            now = 0
            if not q1:
                now = q2.popleft()
            elif not q2:
                now = q1.pop()
            
            elif q1[-1] >= q2[0]:
                now = q1.pop()
            else:
                now = q2.popleft()
            now = max(now - x, 0)
            q2.append(now)
        if sum(q1) + sum(q2) <= b * y:
            return True
        else:
            return False
    ok = 10 ** 9
    ng = -1

    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    return ok
print(solve(n, a, b, x, y, h))
0