def max(a,b); a > b ? a : b; end
  
A_MAX = 100000

N, M = gets.split.map(&:to_i)
A = gets.split.map(&:to_i)
C = Array.new(A_MAX + 10, 0) # C[x] := A.count{|a| a >= x }; C[x] - C[x + 1] := A.count{|a| a == x }
S = Array.new(A_MAX + 10, 0) # S[x] := A.select{|a| a >= x }.sum

A.each{|a| C[a] += 1 }
A_MAX.downto(0) do |i| 
  S[i] = C[i] * i + S[i + 1]
  C[i] += C[i + 1]
end

ANS = {}

xy_ = (1 .. 2 * A_MAX).bsearch do |xy|
  m = 0
  s = 0
  A.each do |x|
    next if xy - x > A_MAX
    m += C[max(xy - x, 0)]
    s += S[max(xy - x, 0)] + C[max(xy - x, 0)] * x
  end
  ANS[xy] = s + (M - m) * (xy - 1)
  m <= M
end
puts ANS[xy_]
