N, M = gets.split.map(&:to_i)
As = gets.split.map(&:to_i).sort.reverse

nn = N
if N > M
  nn = M
end

data = []
nn.times do |i|
  nn.times do |j|
    if i == j
      data << 2 * As[i]
    else
      data << As[i] + As[j]
    end
  end
end

data.sort!.reverse!
ans = 0
M.times do |i|
  break if data[i] == nil
  ans += data[i]
end
puts ans