結果

問題 No.507 ゲーム大会(チーム決め)
ユーザー 👑 obakyanobakyan
提出日時 2020-04-19 20:10:50
言語 Lua
(LuaJit 2.1.1696795921)
結果
RE  
実行時間 -
コード長 839 bytes
コンパイル時間 77 ms
コンパイル使用メモリ 5,248 KB
実行使用メモリ 19,072 KB
最終ジャッジ日時 2024-04-15 22:52:51
合計ジャッジ時間 1,706 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 RE -
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 RE -
testcase_07 AC 69 ms
5,376 KB
testcase_08 RE -
testcase_09 AC 51 ms
5,376 KB
testcase_10 AC 72 ms
11,264 KB
testcase_11 AC 103 ms
18,048 KB
testcase_12 AC 51 ms
5,376 KB
testcase_13 AC 111 ms
19,072 KB
testcase_14 AC 104 ms
17,920 KB
testcase_15 AC 104 ms
18,048 KB
testcase_16 AC 104 ms
18,944 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mfl, mce = math.floor, math.ceil
local mmi, mma = math.min, math.max
local bls, brs = bit.lshift, bit.rshift

local n, m = io.read("*n", "*n")
local a = io.read("*n")
local t = {}
n = n - 1
for i = 1, n do
  t[i] = io.read("*n")
end
table.sort(t)

local function judge(x)
  local tgt = a + t[x]
  local z = {}
  for i = n, 1, -1 do
    if i ~= x then
      table.insert(z, i)
    end
    if 2 * m <= #z then break end
  end
  for i = 1, m do
    if t[z[i]] + t[z[2 * m + 1 - i]] <= tgt then
      return true
    end
  end
  return false
end
if m * 2 == n then
  print(t[1])
elseif not judge(n) then
  print(-1)
elseif judge(1) then
  print(t[1])
else
  local min, max = 1, n
  while 1 < max - min do
    local mid = brs(min + max, 1)
    if judge(mid) then
      max = mid
    else
      min = mid
    end
  end
  print(t[max])
end
0