結果
| 問題 | No.1597 Matrix Sort |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-07-21 20:28:48 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 290 ms / 1,500 ms |
| コード長 | 976 bytes |
| 記録 | |
| コンパイル時間 | 162 ms |
| コンパイル使用メモリ | 5,120 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-17 14:17:10 |
| 合計ジャッジ時間 | 6,784 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 27 |
ソースコード
local mfl, mce = math.floor, math.ceil
local n, k, p = io.read("*n", "*n", "*n")
local a, b = {}, {}
for i = 1, n do
a[i] = io.read("*n")
end
for i = 1, n do
b[i] = io.read("*n")
end
table.sort(a)
table.sort(b)
local function solve(x)
local c1 = 0
local apos = n
for i = 1, n do
while 0 < apos and x < a[apos] + b[i] do
apos = apos - 1
end
if apos == 0 then break end
c1 = c1 + apos
end
apos = n
local c2 = 0
for i = 1, n do
while 0 < apos and p - 1 < a[apos] + b[i] do
apos = apos - 1
end
if apos == 0 then break end
c2 = c2 + apos
end
apos = n
local c3 = 0
for i = 1, n do
while 0 < apos and p + x < a[apos] + b[i] do
apos = apos - 1
end
if apos == 0 then break end
c3 = c3 + apos
end
return k <= c3 - c2 + c1
end
local min, max = -1, p - 1
while 1 < max - min do
local mid = mfl((min + max) / 2)
if solve(mid) then
max = mid
else
min = mid
end
end
print(max)