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