let [|n;m|] = stdin.ReadLine().Split() |> Array.map int
let a = stdin.ReadLine().Split() |> Array.map int

let ls = [for i in 0..(n - 1) do
          for j in 0..(n - 1) -> (a.[i] + a.[j])] |> List.sort

let n_2 = n * n - 1

List.sum [for i in ((n_2 - m) + 1)..(n_2) -> ls.[i]]
|>stdout.WriteLine