結果
問題 | No.710 チーム戦 |
ユーザー |
👑 |
提出日時 | 2022-10-26 22:56:52 |
言語 | Lua (LuaJit 2.1.1734355927) |
結果 |
AC
|
実行時間 | 828 ms / 3,000 ms |
コード長 | 974 bytes |
コンパイル時間 | 61 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 11,904 KB |
最終ジャッジ日時 | 2024-07-04 11:00:36 |
合計ジャッジ時間 | 13,760 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 |
ソースコード
local n = io.read("*n") local a, b = {}, {} local asum = 0 for i = 1, n do a[i], b[i] = io.read("*n", "*n") asum = asum + a[i] end local function solve(x) local need = asum - x local t = {} for i = 1, need - 1 do t[i] = false end local ans = false for i = 1, n do local ai, bi = a[i], b[i] for j = need - 1, 1, -1 do if t[j] then if need <= j + ai then if not ans or t[j] + bi < ans then ans = t[j] + bi end else if not t[j + ai] or t[j] + bi < t[j + ai] then t[j + ai] = t[j] + bi end end end end if ai < need then if not t[ai] or bi < t[ai] then t[ai] = bi end else if not ans or bi < ans then ans = bi end end end return ans and ans <= x end local min, max = 0, asum while 1 < max - min do local mid = math.floor((min + max) / 2) if solve(mid) then max = mid else min = mid end end print(max)