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

score=0
values = []
A.each do |a1|
  values << A.collect{|item| item+a1}
end 

M.times do
  p i
  candidates=[]
  values.each do |v|
    if v==[]
      candidates << 0
    else
      candidates << v[0]
    end
  end
  mx = candidates.max
  idx = candidates.index(mx)
  score += mx
  values[idx].shift
end
    
p score