import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;
static import std.ascii;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M;
    scan(N, M);
    auto A = aryread();
    auto cnt = new long[](10 ^^ 5 + 1);
    foreach (a; A)
        cnt[a]++;
    auto s = cnt.dup; // s[x] := パワーx以上のゲストの数
    foreach_reverse (i; 0 .. (10 ^^ 5))
        s[i] += s[i + 1];
    long eval(long x)
    {
        long ret;
        foreach (a; A)
            ret += (x - a + 1 <= 10 ^^ 5) ? s[max(0, x - a + 1)] : 0;
        return ret;
    }

    long m = () {
        long ok = 0;
        long ng = M * (10 ^^ 5) * 2 + 1;
        while (1 < ng - ok)
        {
            long x = (ng + ok) / 2;
            if (M <= eval(x))
            {
                ok = x;
            }
            else
            {
                ng = x;
            }
        }
        return ok;
    }();

    A.sort!"b<a"();
    auto s2 = new long[](N + 1);
    foreach (i; 0 .. N)
        s2[i + 1] = s2[i] + A[i];

    long ans;
    foreach (a; A)
    {
        long c = (m - a + 1 <= 10 ^^ 5) ? s[max(0, m - a + 1)] : 0;
        ans += s2[c] + a * c;
    }
    writeln(ans - (eval(m) - M) * (m + 1));
}
