結果

問題 No.370 道路の掃除
ユーザー バカらっくバカらっく
提出日時 2018-06-05 14:59:47
言語 Swift
(5.10.0)
結果
WA  
実行時間 -
コード長 522 bytes
コンパイル時間 1,835 ms
コンパイル使用メモリ 135,708 KB
実行使用メモリ 8,336 KB
最終ジャッジ日時 2023-08-20 10:44:33
合計ジャッジ時間 3,325 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
8,144 KB
testcase_01 AC 3 ms
8,148 KB
testcase_02 AC 3 ms
8,112 KB
testcase_03 AC 4 ms
8,064 KB
testcase_04 AC 4 ms
8,196 KB
testcase_05 AC 3 ms
8,144 KB
testcase_06 AC 3 ms
8,144 KB
testcase_07 AC 4 ms
8,144 KB
testcase_08 AC 3 ms
8,132 KB
testcase_09 AC 3 ms
8,128 KB
testcase_10 AC 4 ms
8,184 KB
testcase_11 AC 4 ms
8,140 KB
testcase_12 AC 4 ms
8,212 KB
testcase_13 AC 4 ms
8,072 KB
testcase_14 AC 3 ms
8,144 KB
testcase_15 AC 3 ms
8,072 KB
testcase_16 AC 4 ms
8,132 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
8,188 KB
testcase_20 AC 3 ms
8,084 KB
testcase_21 AC 3 ms
8,084 KB
testcase_22 AC 3 ms
8,128 KB
testcase_23 AC 4 ms
8,112 KB
testcase_24 AC 4 ms
8,272 KB
testcase_25 AC 4 ms
8,120 KB
testcase_26 AC 4 ms
8,312 KB
testcase_27 AC 4 ms
8,200 KB
testcase_28 AC 4 ms
8,112 KB
testcase_29 AC 4 ms
8,168 KB
testcase_30 AC 4 ms
8,336 KB
testcase_31 AC 4 ms
8,080 KB
testcase_32 AC 4 ms
8,212 KB
testcase_33 AC 4 ms
8,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


let inpt = readLine()!.split(separator: " ").map{ Int($0)! }

let mustGet = inpt[0]
let itemCount = inpt[1]

var items = [Int]()

for _ in 0..<itemCount {
    items.append(Int(readLine()!)!)
}

items = items.sorted()

var ans = (items.last! - items.first!) + min(abs(items.last!), abs(items.first!))

for i in 0..<items.count {
    if i + mustGet >= itemCount {
        break
    }
    let temp = (items[i + mustGet - 1] - items[i]) + min(abs(items[i + mustGet - 1]), abs(items[i]))
    ans = min(ans,temp)
}
print(ans)
0