let rec lower_bound l r p =
  if r <= 1 + l
  then r
  else let m = (l + r) / 2 in
       if p m
       then lower_bound l m p
       else lower_bound m r p

let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d %d\n" @@ fun n m ->
  let as_ = Array.init (n + 1) @@ function
    | 0 -> 100000000
    | _ -> Scanf.scanf "%d " @@ fun a -> a in
  Array.sort (fun x y -> compare y x) as_;
  let acc = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    acc.(i + 1) <- acc.(i) + as_.(i + 1)
  done;
  let border = lower_bound 0 1000000 @@ fun b ->
    ( > ) (m + n) @@ Array.fold_right (fun a -> ( + ) @@
    upper_bound 0 (n + 1) @@ fun i -> b < a + as_.(i)) as_ 0 in
  let x, sum =
    Array.fold_left (fun (x, sum) (x', sum') -> x + x', sum + sum') (0, 0) @@
    Array.init n @@ fun i ->
      let x = upper_bound 0 (n + 1) @@ fun j -> border < as_.(i + 1) + as_.(j) in
      x, acc.(x) + x * as_.(i + 1) in
  Printf.printf "%d\n" @@ sum + (m - x) * border
