結果
| 問題 | No.817 Coin donation |
| コンテスト | |
| ユーザー |
norioc
|
| 提出日時 | 2025-06-10 22:51:45 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 135 ms / 2,000 ms |
| コード長 | 801 bytes |
| 記録 | |
| コンパイル時間 | 476 ms |
| コンパイル使用メモリ | 82,176 KB |
| 実行使用メモリ | 82,232 KB |
| 最終ジャッジ日時 | 2025-06-10 22:51:49 |
| 合計ジャッジ時間 | 3,354 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
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)
norioc