n, m = gets.split.map(&:to_i)
list = gets.split.map(&:to_i).sort!{|a,b| b<=>a}
sum_list = []
sum  = 0

n.times do |i|
    (i...n).each do |j|
        if i==j
            sum_list.push(list[i]+list[j])
        else
            sum_list.push(list[i]+list[j])
            sum_list.push(list[i]+list[j])
        end
    end
end

sum_list.sort!{|a,b| b<=>a}
p sum_list.slice(0,m).inject(:+)

