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

A2 = A.sort!.reverse!

# p A2
scores = Array.new
A2.each do |a1|
  A2.each do |a2|
    scores << a1+a2
  end
end

scores.sort!.reverse!

sum = 0

(0..M-1).each do |i|
  sum += scores[i]
end
print sum