let [|n;k|] = stdin.ReadLine().Split() |> Array.map int
let h = stdin.ReadLine().Split() |> Array.map int64

Array.scan (fun x t -> 
    let cost = x |> Array.map (fun (h,c) -> c+(abs (t-h))) |> Array.min
    let l = Array.length x
    if l = k then Array.append x.[1..k-1] [|(t,cost)|]
    else Array.append x [|(t,cost)|]) [|(h.[0],0L)|] h.[1..n-1]
|> ((fun x -> 
    let arr = x.[n-1]
    arr.[(Array.length arr) - 1]) >> (fun (_,c) -> c))
|> stdout.WriteLine