require 'complex'
lines = readlines.map{|line| line.split(' ').map(&:to_i)}
a=lines[1].sort.reverse!
p=[]
b=Math.sqrt(lines[0][1]).ceil
for i in 0..b
  for j in 0..b
    if a[i]!=nil&&a[j]!=nil then
      p.push(a[i]+a[j])
    end
  end
end
c=p.sort.reverse!
p c[0..lines[0][1]-1].inject(:+)