Scanf.scanf "%d %d" (fun n k ->
    let h = Array.init n (fun _ -> Scanf.scanf " %d" (fun h -> h)) in
    Array.sort compare h;
    let rec loop i acc =
        if i < 0 then acc else loop (i - 1) (acc + h.(i))
    in
    let r = loop (max (-1) (n - 1 - k)) 0 in
    Printf.printf "%d\n" r
)