結果

問題 No.1163 I want to be a high achiever
ユーザー 👑 obakyanobakyan
提出日時 2021-08-09 19:04:24
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 111 ms / 2,000 ms
コード長 890 bytes
コンパイル時間 320 ms
コンパイル使用メモリ 5,152 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 16:43:33
合計ジャッジ時間 2,915 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 1 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 39 ms
4,348 KB
testcase_05 AC 74 ms
4,348 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 106 ms
4,348 KB
testcase_08 AC 90 ms
4,348 KB
testcase_09 AC 1 ms
4,348 KB
testcase_10 AC 47 ms
4,348 KB
testcase_11 AC 65 ms
4,348 KB
testcase_12 AC 44 ms
4,348 KB
testcase_13 AC 20 ms
4,348 KB
testcase_14 AC 23 ms
4,348 KB
testcase_15 AC 97 ms
4,348 KB
testcase_16 AC 35 ms
4,348 KB
testcase_17 AC 52 ms
4,348 KB
testcase_18 AC 104 ms
4,348 KB
testcase_19 AC 19 ms
4,348 KB
testcase_20 AC 9 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 68 ms
4,348 KB
testcase_23 AC 57 ms
4,348 KB
testcase_24 AC 111 ms
4,348 KB
testcase_25 AC 35 ms
4,348 KB
testcase_26 AC 1 ms
4,348 KB
testcase_27 AC 1 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 AC 2 ms
4,348 KB
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local mmi, mma = math.min, math.max
local n, x = io.read("*n", "*n")
local a = {}
for i = 1, n do
  a[i] = io.read("*n") - x
end
local b = {}
for i = 1, n do
  b[i] = io.read("*n")
end
local asum = 0
for i = 1, n do
  asum = asum + a[i]
end
if 0 <= asum then
  print(0) os.exit()
end
do
  local f = true
  for i = 1, n do
    if 0 <= a[i] then f = false break end
  end
  if f then print(-1) os.exit() end
end
asum = -asum
local t = {}
for i = 1, asum do t[i] = -1 end
for i = 1, n do
  local ai = a[i]
  local bi = b[i]
  if ai < 0 then
    ai = -ai
    for j = asum, 1, -1 do
      if 0 <= t[j] then
        local dst = mmi(asum, j + ai)
        if t[dst] < 0 or t[j] + bi < t[dst] then
          t[dst] = t[j] + bi
        end
      end
    end
    do
      local dst = mmi(asum, ai)
      if t[dst] < 0 or bi < t[dst] then
        t[dst] = bi
      end
    end
  end
end
print(t[asum])
0