結果
| 問題 |
No.837 Noelちゃんと星々2
|
| コンテスト | |
| ユーザー |
koi_kotya
|
| 提出日時 | 2019-06-15 00:39:44 |
| 言語 | Ruby (3.4.1) |
| 結果 |
AC
|
| 実行時間 | 169 ms / 2,000 ms |
| コード長 | 394 bytes |
| コンパイル時間 | 812 ms |
| コンパイル使用メモリ | 7,680 KB |
| 実行使用メモリ | 20,992 KB |
| 最終ジャッジ日時 | 2024-06-11 14:19:06 |
| 合計ジャッジ時間 | 4,641 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 29 |
コンパイルメッセージ
Syntax OK
ソースコード
n = gets.to_i
a = gets.split.map(&:to_i).sort
u = 0
v = n/2
sum = 0
(1...n).each do |i|
sum += (a[i]-a[v]).abs
end
ans = sum
(1..(n-2)).each do |i|
sum += 2*a[i]-a[u]-a[v]
if i.even?
sum -= a[u+1]-a[u]
u += 1
end
if (n-i).even?
sum -= a[v+1]-a[v]
v += 1
end
ans = sum if ans > sum
end
if a[0] == a[-1]
puts 1
else
puts ans
end
koi_kotya