#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
constexpr array<int, 4> dx = {1, 0, -1, 0};
constexpr array<int, 4> dy = {0, 1, 0, -1};
constexpr int INF = 1234567890;
constexpr int MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int ceil(int a, int b) { return (a + b - 1) / b; }
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}

int countVeryHappyHandshakes(int x, const vector<int> &a, vector<int> &count_of_handshakes_list)
{
    // 幸福度 X 以上の握手は何件かを O(NlogN) で探索する
    const int n = a.size();
    count_of_handshakes_list.resize(n, 0);

    for (int i = 0; i < n; i++)
    {
        // 左手 の幸福度はa[i]とする 右手の幸福度はleft-x以上でなければならない
        const int left = a[i];
        const int right = x - left;

        // 二分探索で条件を満たす握手が何件あるか探す
        if (a[0] < right)
            count_of_handshakes_list[i] = 0;
        else if (a[n - 1] >= right)
            count_of_handshakes_list[i] = n;
        else
        {
            // めぐる式二分探索
            // [ok, ng) または (ng, ok] を探索
            int ok = 0; // 解がある値
            int ng = n; // 解がない値
            while (abs(ok - ng) > 1)
            {
                int mid = (ok + ng) / 2;
                if (a[mid] >= right)
                    ok = mid;
                else
                    ng = mid;
            }
            count_of_handshakes_list[i] = ng;
        }
    }
    return accumulate(count_of_handshakes_list.begin(), count_of_handshakes_list.end(), 0LL);
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int happpiness = 0;

    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    // 降順ソート
    sort(a.rbegin(), a.rend());

    const int max_a = *max_element(a.begin(), a.end());

    // Aの累積和
    vector<int> csa(n + 1);
    csa[0] = 0;
    for (int i = 0; i < n; i++)
        csa[i + 1] = csa[i] + a[i];

    int count_of_handshakes = 0;
    vector<int> count_of_handshakes_list(n);

    // 幸福度 X 以上の握手がM件以上になる最小のXを求める
    // めぐる式二分探索
    // [ok, ng) または (ng, ok] を探索
    int ok = 0;                 // 解がある値
    int ng = max_a + max_a + 1; // 解がない値
    while (abs(ok - ng) > 1)
    {
        int mid = (ok + ng) / 2;
        count_of_handshakes = countVeryHappyHandshakes(mid, a, count_of_handshakes_list);
        if (count_of_handshakes >= m)
            ok = mid;
        else
            ng = mid;
    }
    const int x = ok;

    count_of_handshakes = countVeryHappyHandshakes(x, a, count_of_handshakes_list);

    // 握手の件数はわかった 累積和を使って高速に幸福度を計算する
    for (int i = 0; i < n; i++)
    {
        const int j = count_of_handshakes_list[i];
        happpiness += a[i] * j + csa[j];
    }
    // コーナーケース 握手の件数がM以上のとき，余剰分Xを引く
    happpiness -= (count_of_handshakes - m) * x;

    cout << happpiness << endl;

    // #ifdef DEBUG
    // vector<int> aa(n * n);

    // for (int i = 0; i < n; i++)
    //     for (int j = 0; j < n; j++)
    //     {
    //         aa[i * n + j] = a[i] + a[j];
    //         // cerr << a[i] + a[j] << " ";
    //     }
    // cerr << endl;
    // sort(aa.rbegin(), aa.rend());
    // int happy = 0;
    // for (int i = 0; i < m; i++)
    // {
    //     happy += aa[i];
    // }
    // cerr << happy << endl;
    // #endif
}


Measured memory_bytes: 2560