

from bisect import bisect_left, bisect_right

from itertools import accumulate

def resolve():

    def shake_cnt(x):

        cnt = 0

        pos = 0

        for i in range(N):

            pos = bisect_left(A, x - A[i])

            cnt += N - pos

        return cnt < M # X以上の和がM個未満かどうか



    N, M = list(map(int, input().split()))

    A = list(map(int, input().split()))

    A.sort()



    # 終了時にngにX-1,okにXが入っている。

    ng = 0

    ok = 10 ** 6

    while abs(ok - ng) > 1:

        mid = (ok + ng)//2

        if shake_cnt(mid):

            ok = mid

        else:

            ng = mid



    acc = [0] + list(accumulate(A))

    ans = 0

    for i in range(N):

        pos = bisect_right(A, ng - A[i])

        cnt = N - pos

        ans += cnt * A[i] + (acc[N] - acc[pos])

        M -= cnt

    ans += M * ng

    print(ans)





if __name__ == "__main__":

    resolve()



from bisect import bisect_left

from itertools import accumulate

def resolve():

    def getCount(x):

        count = 0

        for Ai in A:

            idx = bisect_left(A, x - Ai)

            count += N - idx

        return count >= M





    N, M = list(map(int, input().split()))

    A = sorted(map(int, input().split()))

    A_r = A[::-1]

    B = [0] + list(accumulate(A_r))



    MIN = 0

    MAX = 2 * 10 ** 5 + 1

    while MAX - MIN > 1:

        MID = (MIN + MAX) // 2

        if getCount(MID):

            MIN = MID

        else:

            MAX = MID



    ans = 0

    count = 0



    for Ai in A_r:

        idx = bisect_left(A, MIN - Ai)

        ans += Ai * (N - idx) + B[N - idx]

        count += N - idx

    print((ans - (count - M) * MIN))





if __name__ == "__main__":

    resolve()

from bisect import bisect_left, bisect_right
from itertools import accumulate


def resolve():
    def shake_cnt(x):
        cnt = 0
        pos = 0
        for i in range(N):
            pos = bisect_left(A, x - A[i])
            cnt += N - pos
        return cnt < M  # X以上の和がM個未満かどうか

    N, M = list(map(int, input().split()))
    A = list(map(int, input().split()))
    A.sort()
    # 終了時にngにX-1,okにXが入っている。
    ng = 0
    ok = 10**6
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if shake_cnt(mid):
            ok = mid
        else:
            ng = mid
    acc = [0] + list(accumulate(A))
    ans = 0
    for i in range(N):
        pos = bisect_right(A, ng - A[i])
        cnt = N - pos
        ans += cnt * A[i] + (acc[N] - acc[pos])
        M -= cnt
    ans += M * ng
    print(ans)


if __name__ == "__main__":
    resolve()

from bisect import bisect_left
from itertools import accumulate


def resolve():
    def getCount(x):
        count = 0
        for Ai in A:
            idx = bisect_left(A, x - Ai)
            count += N - idx
        return count >= M

    N, M = list(map(int, input().split()))
    A = sorted(map(int, input().split()))
    A_r = A[::-1]
    B = [0] + list(accumulate(A_r))
    MIN = 0
    MAX = 2 * 10**5 + 1
    while MAX - MIN > 1:
        MID = (MIN + MAX) // 2
        if getCount(MID):
            MIN = MID
        else:
            MAX = MID
    ans = 0
    count = 0
    for Ai in A_r:
        idx = bisect_left(A, MIN - Ai)
        ans += Ai * (N - idx) + B[N - idx]
        count += N - idx
    print((ans - (count - M) * MIN))


if __name__ == "__main__":
    resolve()

-from bisect import bisect_left, bisect_right +from bisect import bisect_left -    def shake_cnt(x): -        cnt = 0 -        pos = 0 -        for i in range(N): -            pos = bisect_left(A, x - A[i]) -            cnt += N - pos -        return cnt < M  # X以上の和がM個未満かどうか +    def getCount(x): +        count = 0 +        for Ai in A: +            idx = bisect_left(A, x - Ai) +            count += N - idx +        return count >= M -    A = list(map(int, input().split())) -    A.sort() -    # 終了時にngにX-1,okにXが入っている。 -    ng = 0 -    ok = 10**6 -    while abs(ok - ng) > 1: -        mid = (ok + ng) // 2 -        if shake_cnt(mid): -            ok = mid +    A = sorted(map(int, input().split())) +    A_r = A[::-1] +    B = [0] + list(accumulate(A_r)) +    MIN = 0 +    MAX = 2 * 10**5 + 1 +    while MAX - MIN > 1: +        MID = (MIN + MAX) // 2 +        if getCount(MID): +            MIN = MID -            ng = mid -    acc = [0] + list(accumulate(A)) +            MAX = MID -    for i in range(N): -        pos = bisect_right(A, ng - A[i]) -        cnt = N - pos -        ans += cnt * A[i] + (acc[N] - acc[pos]) -        M -= cnt -    ans += M * ng -    print(ans) +    count = 0 +    for Ai in A_r: +        idx = bisect_left(A, MIN - Ai) +        ans += Ai * (N - idx) + B[N - idx] +        count += N - idx +    print((ans - (count - M) * MIN))