N, M = gets.chomp.split(" ").map(&:to_i)
A = gets.chomp.split(" ").map(&:to_i)

a = A.combination(2).map{|a, b| a + b}.sort.reverse
b = A.map{|e| 2 * e}.sort.reverse
ans, c, ia, ib = [0, 0, 0, 0]
while c < M do
  if a[ia] > b[ib] || ib == b.size then
    if M - c == 1 then
      ans += a[ia]
      c += 1
    else
      ans += 2 * a[ia]
      c += 2
    end
    ia += 1
  else
    ans += b[ib]
    ib += 1
    c += 1
  end
end

puts ans
