結果

問題 No.370 道路の掃除
ユーザー cympfhcympfh
提出日時 2016-05-13 22:37:04
言語 Ruby
(3.3.0)
結果
WA  
実行時間 -
コード長 665 bytes
コンパイル時間 297 ms
コンパイル使用メモリ 7,552 KB
実行使用メモリ 12,416 KB
最終ジャッジ日時 2024-04-15 16:35:30
合計ジャッジ時間 4,287 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
12,288 KB
testcase_01 AC 85 ms
12,160 KB
testcase_02 AC 89 ms
12,288 KB
testcase_03 AC 86 ms
12,160 KB
testcase_04 WA -
testcase_05 AC 88 ms
12,288 KB
testcase_06 WA -
testcase_07 AC 85 ms
12,160 KB
testcase_08 WA -
testcase_09 AC 85 ms
12,160 KB
testcase_10 AC 84 ms
12,160 KB
testcase_11 AC 86 ms
12,160 KB
testcase_12 AC 85 ms
12,288 KB
testcase_13 AC 86 ms
12,288 KB
testcase_14 AC 87 ms
12,160 KB
testcase_15 AC 88 ms
12,416 KB
testcase_16 AC 87 ms
12,160 KB
testcase_17 AC 86 ms
12,288 KB
testcase_18 AC 89 ms
12,160 KB
testcase_19 AC 88 ms
12,288 KB
testcase_20 AC 87 ms
12,288 KB
testcase_21 AC 93 ms
12,288 KB
testcase_22 AC 91 ms
12,160 KB
testcase_23 AC 85 ms
12,160 KB
testcase_24 AC 87 ms
12,160 KB
testcase_25 AC 86 ms
12,160 KB
testcase_26 AC 88 ms
12,160 KB
testcase_27 AC 88 ms
12,288 KB
testcase_28 AC 88 ms
12,160 KB
testcase_29 AC 88 ms
12,160 KB
testcase_30 AC 88 ms
12,416 KB
testcase_31 AC 91 ms
12,160 KB
testcase_32 AC 88 ms
12,288 KB
testcase_33 AC 89 ms
12,416 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

n,m=gets.chomp.split.map(&:to_i)
ds = m.times.map{ gets.to_i }

if n == 1
  p ds[0].abs
  exit 0
end

xs = ds.select{|x| x < 0 }.map{|x| -x}.sort
ys = ds.select{|x| x > 0 }.sort

if ds.select{|x| x == 0}.length > 0
  n -= 1
end

ans = 1e10

if xs.size >= n
  ans = [ans, xs[n-1]].min
end
if ys.size >= n
  ans = [ans, ys[n-1]].min
end

for k in 0..xs.size do
  if k < n and n-k-1 < ys.size
    d = (k == 0 ? 0 : xs[k-1]) * 2 + (n==k ? 0 : ys[n-k-1])
    ans = [ans, d].min
  end
end

xs,ys = ys,xs
# p [xs,ys]

for k in 0..xs.size do
  if k < n and n-k-1 < ys.size
    d = (k == 0 ? 0 : xs[k-1]) * 2 + (n==k ? 0 : ys[n-k-1])
    ans = [ans, d].min
  end
end

p ans
0