lines = readlines.map{|line| line.split(' ').map(&:to_i)}
a=lines[1].sort.reverse!
p=a[0..(lines[0][1]/2).to_i+1].repeated_permutation(2).to_a
b=[]
for i in p
  b.push(i[0]+i[1])
end
d=0
c=b.sort.reverse!
p c[0..lines[0][1]-1].inject(:+)