結果

問題 No.710 チーム戦
ユーザー 👑 obakyanobakyan
提出日時 2022-10-26 22:56:52
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 895 ms / 3,000 ms
コード長 974 bytes
コンパイル時間 36 ms
コンパイル使用メモリ 5,212 KB
実行使用メモリ 10,508 KB
最終ジャッジ日時 2023-09-17 16:04:09
合計ジャッジ時間 14,041 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 625 ms
8,888 KB
testcase_03 AC 750 ms
8,816 KB
testcase_04 AC 689 ms
9,012 KB
testcase_05 AC 650 ms
8,732 KB
testcase_06 AC 657 ms
6,556 KB
testcase_07 AC 680 ms
8,968 KB
testcase_08 AC 685 ms
8,644 KB
testcase_09 AC 374 ms
9,348 KB
testcase_10 AC 566 ms
6,356 KB
testcase_11 AC 572 ms
8,604 KB
testcase_12 AC 673 ms
9,608 KB
testcase_13 AC 380 ms
9,540 KB
testcase_14 AC 680 ms
8,976 KB
testcase_15 AC 355 ms
6,096 KB
testcase_16 AC 400 ms
9,092 KB
testcase_17 AC 537 ms
6,060 KB
testcase_18 AC 629 ms
8,336 KB
testcase_19 AC 728 ms
9,120 KB
testcase_20 AC 613 ms
6,092 KB
testcase_21 AC 638 ms
7,932 KB
testcase_22 AC 81 ms
9,412 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 895 ms
10,508 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0