結果

問題 No.817 Coin donation
ユーザー 👑 KazunKazun
提出日時 2021-02-10 17:54:59
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 1,299 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 84,056 KB
最終ジャッジ日時 2023-09-22 12:39:24
合計ジャッジ時間 2,929 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,304 KB
testcase_01 AC 71 ms
71,432 KB
testcase_02 AC 76 ms
75,388 KB
testcase_03 AC 76 ms
75,332 KB
testcase_04 AC 73 ms
71,240 KB
testcase_05 AC 86 ms
76,696 KB
testcase_06 AC 90 ms
76,776 KB
testcase_07 AC 95 ms
77,472 KB
testcase_08 AC 127 ms
83,760 KB
testcase_09 AC 97 ms
78,208 KB
testcase_10 AC 145 ms
83,712 KB
testcase_11 AC 143 ms
83,940 KB
testcase_12 AC 142 ms
84,056 KB
testcase_13 AC 73 ms
71,116 KB
testcase_14 AC 72 ms
71,448 KB
testcase_15 AC 73 ms
71,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

def General_Binary_Increase_Search(L,R,cond,Integer=True,ep=1/(1<<20),Times=50):
    """条件式が単調増加であるとき,一般的な二部探索を行う.
    L:解の下限
    R:解の上限
    cond:条件(1変数関数,広義単調減少 or 広義単調減少を満たす)
    Integer:解を整数に制限するか?
    ep:Integer=Falseのとき,解の許容する誤差
    """
    if not(cond(R)):
        return None

    if cond(L):
        return L

    if Integer:
        R+=1
        while R-L>1:
            C=L+(R-L)//2
            if cond(C):
                R=C
            else:
                L=C
        return R
    else:
        while (R-L)>=ep and Times:
            Times-=1
            C=L+(R-L)/2
            if cond(C):
                R=C
            else:
                L=C
        return R
#================================================
def check(x):
    M=0
    for i in range(N):
        M+=max(0,min(Y[i],x)-X[i]+1)
    return M>=K
#================================================
import sys
input=sys.stdin.readline
N,K=map(int,input().split())
X=[]
X_append=X.append
Y=[]
Y_append=Y.append
Sum=0
for _ in range(N):
    a,b=map(int,input().split())
    X_append(a)
    Y_append(b)
    Sum+=b-a+1

print(General_Binary_Increase_Search(0,10**10,check))
0