結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 2 ms
4,348 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 1 ms
4,348 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 2 ms
4,348 KB
testcase_27 AC 2 ms
4,348 KB
testcase_28 AC 1 ms
4,348 KB
testcase_29 WA -
testcase_30 AC 1 ms
4,348 KB
testcase_31 AC 1 ms
4,348 KB
testcase_32 AC 1 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
      local dst = mmi(asum, j + ai)
      if t[dst] < 0 or t[j] + bi < t[dst] then
        t[dst] = t[j] + bi
      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