結果

問題 No.817 Coin donation
コンテスト
ユーザー norioc
提出日時 2025-06-10 22:51:45
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 801 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 91 ms
コンパイル使用メモリ 64,768 KB
実行使用メモリ 68,864 KB
最終ジャッジ日時 2026-10-14 11:20:31
合計ジャッジ時間 3,108 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 1
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

def bsearch(low: int, high: int, fun, is_complement=False) -> int:
    def pred(x: int) -> bool:
        return not fun(x) if is_complement else fun(x)

    lo = low
    hi = high
    res = low
    while lo <= hi:
        m = (lo + hi) // 2
        if pred(m):
            res = max(res, m)
            lo = m + 1
        else:
            hi = m - 1

    return res + 1 if is_complement else res


# m 円以下が K 枚以上あるか
def calc(m: int) -> bool:
    res = 0
    for a, b in xs:
        if m < a: continue
        res += min(m, b) - a + 1
        if res >= K:
            return True

    return False


N, K = map(int, input().split())
xs = []
for _ in range(N):
    A, B = map(int, input().split())
    xs.append((A, B))

ans = bsearch(1, 10**9, calc, is_complement=True)
print(ans)
0