結果

問題 No.198 キャンディー・ボックス2
ユーザー fine
提出日時 2016-01-11 00:47:05
言語 Ruby
(3.4.1)
結果
AC  
実行時間 87 ms / 1,000 ms
コード長 314 bytes
コンパイル時間 88 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,288 KB
最終ジャッジ日時 2024-11-16 09:46:40
合計ジャッジ時間 3,880 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

b = gets.to_i
n = gets.to_i
c = STDIN.map(&:to_i)
c_uniq = c.uniq.push((c.inject(&:+) + b) / n)
ans = []
c_uniq.each{|standard|
    give = b
    sum = 0
    c.each{|candy|
        tmp = candy - standard
        give += tmp
        sum += tmp.abs
    }
    if give >= 0
        ans.push(sum)
    end
    }
p ans.min
0