結果

問題 No.817 Coin donation
ユーザー roarisroaris
提出日時 2019-08-14 21:34:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 218 ms / 2,000 ms
コード長 600 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 81,864 KB
実行使用メモリ 84,292 KB
最終ジャッジ日時 2023-10-19 18:14:41
合計ジャッジ時間 2,484 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,628 KB
testcase_01 AC 38 ms
53,628 KB
testcase_02 AC 41 ms
59,200 KB
testcase_03 AC 42 ms
59,200 KB
testcase_04 AC 40 ms
59,200 KB
testcase_05 AC 71 ms
72,992 KB
testcase_06 AC 93 ms
76,620 KB
testcase_07 AC 100 ms
76,652 KB
testcase_08 AC 171 ms
81,264 KB
testcase_09 AC 105 ms
76,684 KB
testcase_10 AC 216 ms
84,292 KB
testcase_11 AC 217 ms
84,292 KB
testcase_12 AC 218 ms
84,288 KB
testcase_13 AC 37 ms
53,628 KB
testcase_14 AC 37 ms
53,628 KB
testcase_15 AC 38 ms
53,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def judge(x):
    cnt = 0
    
    for Ai, Bi in AB:
        if Ai <= x <= Bi:
            cnt += x - Ai + 1
        elif Bi < x:
            cnt += Bi - Ai + 1
    
    if cnt >= K:
        return True
    else:
        return False
    
def binary_search():
    left, right = 0, 10 ** 18
    
    while left <= right:
        mid = (left + right) // 2
        
        if judge(mid):
            right = mid - 1
        else:
            left = mid + 1
    
    return left

N, K = map(int, input().split())
AB = [tuple(map(int, input().split())) for _ in range(N)]
ans = binary_search()
print(ans)
0