結果
| 問題 | No.198 キャンディー・ボックス2 |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-05-05 11:14:15 |
| 言語 | Lua (LuaJit 2.1.1734355927) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 1,000 ms |
| コード長 | 388 bytes |
| コンパイル時間 | 306 ms |
| コンパイル使用メモリ | 7,972 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-11-26 11:43:12 |
| 合計ジャッジ時間 | 1,229 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 27 |
ソースコード
local ior = io.input()
local b, n = ior:read("*n", "*n")
local t = {}
local sum = 0
for i = 1, n do
local a = ior:read("*n")
t[i], sum = a, sum + a
end
table.sort(t)
local midpos = math.floor((n + 1) / 2)
local dstval = t[midpos]
if(sum + b < dstval * n) then
dstval = math.floor((sum + b) / n)
end
local cnt = 0
for i = 1, n do
cnt = cnt + math.abs(t[i] - dstval)
end
print(cnt)