import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto nm = readln.split.to!(long[]);
    auto N = nm[0];
    auto M = nm[1];
    auto as = readln.split.to!(long[]);
    sort!"a > b"(as);

    auto cs = new long[](N);
    foreach_reverse (i; 0..N) {
        if (i+1 < N) cs[i] = cs[i+1];
        cs[i] += as[i];
    }
    long r;
    size_t x;
    foreach (i; 0..N) {
        if (M == 0) break;
        long a = x, b = N;
        bool has_d;
        auto min_a = as[i] + as[N-1];
        if (x < N && as[N-1]*2 >= min_a) {
            has_d = true;
            a = N-1;
            b = N;
        } else if (x < N && as[x]*2 >= min_a) {
            has_d = true;
            while (a+1 < b) {
                auto m = (a+b)/2;
                if (as[m]*2 >= min_a) {
                    a = m;
                } else {
                    b = m;
                }
            }
        }
        auto t = (N-i-1)*2 + (has_d ? a-x+1 : 0);
        if (t <= M) {
            M -= t;
            if (has_d) foreach (j; x..b) r += as[j]*2;
            x = b;
            if (i != N-1) r += (cs[i+1] + as[i] * (N-i-1)) * 2;
        } else {
            long[] rs;
            if (has_d) foreach (j; x..N) rs ~= as[j]*2;
            foreach (j; i+1..N) {
                rs ~= as[i] + as[j];
                rs ~= as[i] + as[j];
            }
            sort!"a > b"(rs);
            foreach (j; 0..M) r += rs[j];
            M = 0;
        }

    }
    writeln(r);
}