#!/usr/bin/ruby

N, M = gets.chomp.split(" ").map(&:to_i)
A  = gets.chomp.split(" ").map(&:to_i)

cmb = []

A.each{|e1|
  A.each{|e2|
    cmb << e1 + e2
  }
}

cmb.sort_by!{|n| -n}

total = 0
0.upto(M-1){|i|
  total += cmb[i]
}

puts total
