結果

問題 No.198 キャンディー・ボックス2
ユーザー 小指が強い人小指が強い人
提出日時 2015-11-20 01:06:49
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 503 bytes
コンパイル時間 367 ms
コンパイル使用メモリ 11,508 KB
実行使用メモリ 15,396 KB
最終ジャッジ日時 2023-10-11 18:07:25
合計ジャッジ時間 4,772 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 78 ms
15,288 KB
testcase_03 AC 78 ms
15,332 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 78 ms
15,320 KB
testcase_09 AC 78 ms
15,084 KB
testcase_10 AC 79 ms
15,280 KB
testcase_11 AC 79 ms
15,356 KB
testcase_12 AC 78 ms
15,236 KB
testcase_13 WA -
testcase_14 AC 78 ms
15,304 KB
testcase_15 AC 78 ms
15,052 KB
testcase_16 AC 80 ms
15,316 KB
testcase_17 AC 79 ms
15,240 KB
testcase_18 AC 80 ms
15,396 KB
testcase_19 WA -
testcase_20 AC 79 ms
15,284 KB
testcase_21 WA -
testcase_22 AC 78 ms
14,992 KB
testcase_23 WA -
testcase_24 AC 79 ms
15,096 KB
testcase_25 WA -
testcase_26 AC 79 ms
15,092 KB
testcase_27 AC 78 ms
15,156 KB
testcase_28 WA -
testcase_29 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

b = gets.to_i
n = gets.to_i
c = Array.new
n.times do
    c.push(gets.to_i)
end
minv = 10 ** 9
mini = 0
c.sort!
n.times do |i|
    sum = 0
    n.times do |j|
        sum += (c[i] - c[j]).abs
    end
    if sum < minv
        minv = sum
        mini = i
    end
end
s1 = 0
s2 = b
n.times do |i|
    if i < mini
        s1 += c[mini] - c[i]
    else
        s2 += c[i] - c[mini]
    end
end
if s1 <= s2
    puts s1 + s2 - b
else
    mc = (s1 - s2) / n + 1
    upc = n - mini
    puts s1 + mc * upc + s2
end
0