let solve k a_arr = let a_arr' = List.sort (fun a1 a2 -> a2 - a1) a_arr in let len_a_arr' = List.length a_arr' in let rec solve' idx acc = if idx >= len_a_arr' || idx >= k then acc else ( let cur_a = List.nth a_arr' idx in if cur_a <= 0 then acc else solve' (idx + 1) (acc + cur_a) ) in solve' 1 (List.nth a_arr' 0) let () = let n, k = read_line () |> fun l -> Scanf.sscanf l "%d %d" (fun n k -> (n, k)) and a_arr = read_line () |> String.split_on_char ' ' |> List.map int_of_string in Printf.printf "%d\n" @@ solve k a_arr