participants_count, shake_count = gets.split.map(&:to_i)
powers = gets.split.map(&:to_i).sort.reverse

get_point = 0
shake_powers = []

(0..Math.sqrt(shake_count)).each do |i|
  (0..Math.sqrt(shake_count)).each do |j|
    shake_powers << (powers[i] + powers[j])
  end
end

shake_powers = shake_powers.sort.reverse

(0..(shake_count-1)).each do |i|
  get_point += shake_powers[i]
end

puts get_point