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

score=0
scores = []

A.each do |a1|
  A.each do |a2|
    scores << a1 + a2
  end
end

M.times do
  curmax = scores.max
  idx = scores.index(curmax)
  score += curmax
  scores.delete_at(idx)
end

p score