結果

問題 No.817 Coin donation
ユーザー 👑 obakyanobakyan
提出日時 2019-09-17 14:17:16
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 555 bytes
コンパイル時間 95 ms
コンパイル使用メモリ 5,220 KB
実行使用メモリ 4,616 KB
最終ジャッジ日時 2023-09-21 16:50:59
合計ジャッジ時間 1,541 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 13 ms
4,380 KB
testcase_08 AC 54 ms
4,616 KB
testcase_09 AC 16 ms
4,380 KB
testcase_10 AC 74 ms
4,380 KB
testcase_11 AC 70 ms
4,376 KB
testcase_12 AC 72 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl = math.floor
local n, k = io.read("*n", "*n")
local a, b ={}, {}
for i = 1, n do
  a[i], b[i] = io.read("*n", "*n")
end

local function solve(x)
  local cnt = 0
  for i = 1, n do
    if b[i] <= x then
      cnt = cnt + b[i] - a[i] + 1
    elseif a[i] <= x then
      cnt = cnt + x - a[i] + 1
    end
  end
  if cnt <= k - 1 then
    return false
  else
    return true
  end
end
local min, max = 0, 1000000000
while 1 < max - min do
  local mid = mfl((max + min) / 2)
  if solve(mid) then
    max = mid
  else
    min = mid
  end
end
print(max)
0