結果

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

テストケース

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

ソースコード

diff #

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

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