結果

問題 No.817 Coin donation
ユーザー koi_kotyakoi_kotya
提出日時 2019-04-19 22:18:52
言語 Ruby
(3.1.1p18 )
結果
AC  
実行時間 669 ms / 2,000 ms
コード長 388 bytes
コンパイル時間 53 ms
使用メモリ 15,556 KB
最終ジャッジ日時 2022-11-22 11:42:58
合計ジャッジ時間 5,259 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 74 ms
13,988 KB
testcase_01 AC 75 ms
13,820 KB
testcase_02 AC 75 ms
13,796 KB
testcase_03 AC 75 ms
13,728 KB
testcase_04 AC 74 ms
13,960 KB
testcase_05 AC 96 ms
14,088 KB
testcase_06 AC 153 ms
14,180 KB
testcase_07 AC 188 ms
14,088 KB
testcase_08 AC 476 ms
14,888 KB
testcase_09 AC 192 ms
14,176 KB
testcase_10 AC 659 ms
15,384 KB
testcase_11 AC 661 ms
15,392 KB
testcase_12 AC 669 ms
15,556 KB
testcase_13 AC 77 ms
13,828 KB
testcase_14 AC 77 ms
13,880 KB
testcase_15 AC 78 ms
13,800 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n,k = gets.split.map(&:to_i)
a,b = 2.times.map{Array.new(n,0)}
n.times do |i|
    a[i],b[i] = gets.split.map(&:to_i)
end
min = 1
max = 10**15
while max-min > 1
    mid = (min+max)/2
    cnt = 0
    n.times do |i|
        if a[i] <= mid
            cnt += (b[i] < mid ? b[i] : mid)-a[i]+1
        end
    end
    if cnt < k
        min = mid
    else
        max = mid
    end
end
puts max
0