N,M = gets.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i).sort.reverse
@count = Array.new(A[0]+1,0)
A.each do |a|
  @count[a] += 1
end

A[0].times do |i|
  @count[-i-2] += @count[-i-1]
end

def 点以上取れるパターン数 x
  count = 0
  N.times do |i|
    point = x - A[i]
    if point < 0
      count += N 
    else
      count += @count[point] || 0
    end
    #if A[0] >= point
    #  left = 0
    #  right = N
    #  while(left+1<right) do
    #    a = (left + right) >>1
    #    if A[a] >= point 
    #      left = a
    #    else
    #      right = a
    #    end
    #  end
    #  count += left + 1
    #end
  end
  count
end

left = 0
right = A[0]*2 + 1
while(left+1<right) do
  x = (left + right) >>1
  m = 点以上取れるパターン数(x)
  # p [x, m]
  if m >= M
    left = x
  else
    right = x
  end
end
x = left
result = []
m = 0
N.times do |i|
  need = x - A[i]
  need = 1 if need <= 0 
  (@count[need]||0).times do |j|
    if A[i] + A[j] >= x
      result.push(A[i] + A[j])
    else
      break
    end
  end
end

# p x
# p [M, m]
r = 0
result.sort.reverse[0..M-1].each do |i|
  r+= i
end
puts r