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