結果

問題 No.1374 Absolute Game
ユーザー 👑 obakyanobakyan
提出日時 2022-04-28 09:27:38
言語 Lua
(LuaJit 2.1.1696795921)
結果
AC  
実行時間 128 ms / 2,000 ms
コード長 347 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 5,328 KB
実行使用メモリ 4,504 KB
最終ジャッジ日時 2023-09-10 16:47:28
合計ジャッジ時間 4,224 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,504 KB
testcase_08 AC 21 ms
4,384 KB
testcase_09 AC 95 ms
4,376 KB
testcase_10 AC 106 ms
4,376 KB
testcase_11 AC 39 ms
4,380 KB
testcase_12 AC 37 ms
4,380 KB
testcase_13 AC 81 ms
4,380 KB
testcase_14 AC 128 ms
4,380 KB
testcase_15 AC 74 ms
4,380 KB
testcase_16 AC 124 ms
4,380 KB
testcase_17 AC 74 ms
4,376 KB
testcase_18 AC 126 ms
4,380 KB
testcase_19 AC 74 ms
4,380 KB
testcase_20 AC 26 ms
4,380 KB
testcase_21 AC 36 ms
4,376 KB
testcase_22 AC 70 ms
4,376 KB
testcase_23 AC 8 ms
4,380 KB
testcase_24 AC 18 ms
4,384 KB
testcase_25 AC 21 ms
4,376 KB
testcase_26 AC 38 ms
4,380 KB
testcase_27 AC 55 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

local n = io.read("*n")
local a = {}
local asum = 0
for i = 1, n do
  a[i] = io.read("*n")
  asum = asum + a[i]
end
if 0 <= asum then
  table.sort(a, function(x, y) return x > y end)
else
  table.sort(a)
end
local x, y = 0, 0
for i = 1, n do
  if i % 2 == 1 then
    x = x + a[i]
  else
    y = y + a[i]
  end
end
print(math.abs(x) - math.abs(y))
0