結果
| 問題 |
No.198 キャンディー・ボックス2
|
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2016-03-27 02:08:18 |
| 言語 | Ruby (3.4.1) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 927 bytes |
| コンパイル時間 | 69 ms |
| コンパイル使用メモリ | 7,552 KB |
| 実行使用メモリ | 12,416 KB |
| 最終ジャッジ日時 | 2024-10-02 01:14:18 |
| 合計ジャッジ時間 | 3,123 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 19 WA * 7 |
コンパイルメッセージ
Main.rb:11: warning: assigned but unused variable - answer Syntax OK
ソースコード
class Yukicoder
def initialize
remain = gets.to_i
n = gets.to_i
candy = []
n.times do
candy << gets.to_i
end
answer = 0
if candy.size == 1
puts "0"
return
end
a = 0
b = candy.max
answer = candy.inject(:+)
while a < b-2
c = a + (b-a)/3
d = [a + 2 * ((b-a)/3), b].min
v1 = candy.inject(0){|sum,i| sum += (c < i)? i-c : c-i}
v2 = candy.inject(0){|sum,i| sum += (d < i)? i-d : d-i}
if v1 < v2
b = d
else
a = c+1
end
end
min_val = Float::INFINITY
(a-100).upto(b+100) do |i|
up_val = 0
down_val = 0
candy.each do |c|
if c < i
up_val += i-c
else
down_val += c-i
end
end
if up_val <= remain + down_val
min_val = [min_val, down_val + up_val].min
end
end
puts min_val
end
end
Yukicoder.new
siman