結果

問題 No.798 コレクション
ユーザー 👑 obakyanobakyan
提出日時 2022-04-20 22:39:26
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 611 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 5,272 KB
実行使用メモリ 4,372 KB
最終ジャッジ日時 2023-09-02 18:20:00
合計ジャッジ時間 2,595 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,372 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 1 ms
4,368 KB
testcase_08 AC 1 ms
4,368 KB
testcase_09 AC 1 ms
4,368 KB
testcase_10 AC 1 ms
4,372 KB
testcase_11 AC 1 ms
4,368 KB
testcase_12 AC 1 ms
4,368 KB
testcase_13 AC 5 ms
4,368 KB
testcase_14 AC 6 ms
4,368 KB
testcase_15 AC 6 ms
4,372 KB
testcase_16 AC 3 ms
4,368 KB
testcase_17 AC 5 ms
4,368 KB
testcase_18 AC 7 ms
4,372 KB
testcase_19 AC 6 ms
4,368 KB
testcase_20 AC 3 ms
4,368 KB
testcase_21 AC 4 ms
4,372 KB
testcase_22 AC 5 ms
4,368 KB
testcase_23 AC 1 ms
4,372 KB
testcase_24 AC 7 ms
4,372 KB
testcase_25 AC 7 ms
4,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local n = io.read("*n")
local a, b = {}, {}
local idx = {}
for i = 1, n do
  a[i], b[i] = io.read("*n", "*n")
  idx[i] = i
end
table.sort(idx, function(x, y) return b[x] > b[y] end)
local trim = math.floor(n / 3)
local lim = n - trim
local t = {}
local inf = 1000000007 * 1000000007
for i = 1, lim do
  t[i] = inf
end
for i_ = 1, n do
  local i = idx[i_]
  local ai, bi = a[i], b[i]
  for j = lim - 1, 0, -1 do
    local src = j == 0 and 0 or t[j]
    local cost = ai + bi * j
    t[j + 1] = mmi(t[j + 1], src + cost)
  end
  -- print(table.concat(t, " "))
end
print(t[lim])
0