let rec fix ~f x = f (fix ~f) x

let rec lower_bound_int ~f l r =
  if l >= r then r
  else
    let m = (l+r) / 2 in
    if f m then lower_bound_int f l m
           else lower_bound_int f (m+1) r

let () =
  Scanf.scanf "%d %d" @@ fun n m ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  Array.sort (-) a;
  let sa =
    fix 0 0 ~f:(fun f i acc -> if i >= n then [acc] else acc :: (f (i+1) (acc+a.(i))))
    |> Array.of_list
  in
  let p =
    lower_bound_int 0 200001 ~f:(fun mp ->
      let co =
        Array.fold_left (fun c u ->
          let i = lower_bound_int (fun j -> u + a.(j) >= mp) 0 n in
          c + (n - i)) 0 a
      in co < m)
    |> pred
  in
  let co, tot =
    Array.fold_left (fun (c, tot) u ->
      let i = lower_bound_int (fun j -> u + a.(j) >= p) 0 n in
      (c + (n - i), tot + u * (n - i) + sa.(n) - sa.(i))) (0, 0) a
  in
  Printf.printf "%d\n" (tot - (co - m) * p)
