#define STOPIT
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#ifndef STOPIT
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& tuple_input_impl(std::istream& os, Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { (void)std::initializer_list<int>{((void)(os >> std::get< Inds >(tuple)), 0)...}; return os; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& operator>> (std::istream& os, Tuple<Args...>& tuple)
  { return tuple_input_impl(os, tuple, std::index_sequence_for<Args...>()); }

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& tuple_output_impl(std::ostream& os, const Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { os << "("; (void)std::initializer_list<int>{((void)(os << (Inds > 0 ? "," : "") << std::get< Inds >(tuple)), 0)...}; return os << ")"; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& operator<< (std::ostream& os, const Tuple<Args...>& tuple)
 { return tuple_output_impl(os, tuple, std::index_sequence_for<Args...>()); }

/*
二分探索です。
スコア X 以上の握手をすると決めたら、左手を全探索です。
左手が x のとき、X - x 以上のものは握手するので、i = lb(X-x) として n - i 回です。
スコアは cum(n) - cum(i) です。
*/

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  lint n, m; std::cin >> n >> m;
  std::vector<lint> a(n); std::cin>>a;
  std::sort(all(a));
  std::vector<lint> cum(n+1,0);
  std::partial_sum(all(a), std::next(cum.begin()));

  auto check = [&] (lint X) {
    lint count = 0, score = 0;
    for (lint x : a) {
      auto lb = std::lower_bound(all(a), X - x);
      int i = lb - a.begin();
      int c = n - i;
      lint v = cum.at(n) - cum.at(i);
      count += c;
      score += v + c * x;
    }
    return std::make_pair(count,score);
  };

  lint lwr = 0, upr = 1e12;
  while (1 < upr - lwr) {
    lint mid = (lwr + upr) / 2;
    lint count,score; std::tie(count,score) = check(mid);
    (count <= m ? upr : lwr) = mid;
  }
  lint X = upr;
  lint count,score; std::tie(count,score) = check(X);
  debug(X,count,score);

  auto border = [&] {
    lint max = 0;
    for (lint x : a) {
      auto lb = std::lower_bound(all(a),X-x);
      if (lb==a.begin())continue;
      lint y = *std::prev(lb);
      debug(x,y,std::vector<int>(a.begin(),lb),std::vector<int>(lb,a.end()));
      cmx(max,x+y);
    }
    return max;
  }();
  debug(X,border);
  score += (m - count) * border;
  std::cout << score << std::endl;
  return 0;
}

Measured memory_bytes: 1792