結果
| 問題 | 
                            No.1374 Absolute Game
                             | 
                    
| コンテスト | |
| ユーザー | 
                            👑  | 
                    
| 提出日時 | 2022-04-28 09:27:38 | 
| 言語 | Lua  (LuaJit 2.1.1734355927)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 100 ms / 2,000 ms | 
| コード長 | 347 bytes | 
| コンパイル時間 | 80 ms | 
| コンパイル使用メモリ | 6,688 KB | 
| 実行使用メモリ | 6,944 KB | 
| 最終ジャッジ日時 | 2024-06-28 07:53:55 | 
| 合計ジャッジ時間 | 2,565 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 26 | 
ソースコード
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))