結果

問題 No.817 Coin donation
ユーザー simansiman
提出日時 2021-01-13 18:52:25
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 345 bytes
コンパイル時間 58 ms
コンパイル使用メモリ 11,556 KB
実行使用メモリ 21,984 KB
最終ジャッジ日時 2023-08-14 16:14:25
合計ジャッジ時間 4,457 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
15,108 KB
testcase_01 AC 63 ms
15,016 KB
testcase_02 AC 65 ms
15,244 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 65 ms
15,088 KB
testcase_14 AC 64 ms
15,228 KB
testcase_15 AC 67 ms
15,048 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, K = gets.split.map(&:to_i)
Q = N.times.map { gets.split.map(&:to_i) }

def f(x)
  rank = 0

  Q.each do |a, b|
    if b < x
      rank += (b - a + 1)
    else
      rank += (x - a + 1)
    end
  end

  K <= rank
end

ok = 10 ** 9
ng = 0

while (ok - ng).abs >= 2
  x = (ok + ng) / 2

  if f(x)
    ok = x
  else
    ng = x
  end
end

puts ok
0