######################

# AC: ms(PyPy)

# AC: ms(Python3)

######################



from bisect import bisect_left

import sys

input = sys.stdin.readline





def main():

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

    A = [int(i) for i in input().split()]



    A.sort()



    left = 0

    right = A[-1] * 2 + 5

    while right - left > 1:

        X = (left + right) // 2



        count = 0

        for a in A:

            i = bisect_left(A, X-a)

            count += (N - i)



        if count >= M:

            left = X

        else:

            right = X



    count = 0

    num = []

    append = num.append

    for a in A:

        i = bisect_left(A, left-a)

        count += (N - i)

        append(N - i)



    diff = count - M

    ans = 0

    for i, a in zip(num, A):

        ans += i * a



    print((ans * 2 - diff * left))





if __name__ == "__main__":

    main()

import numpy as np

import sys

input = sys.stdin.readline





def main():

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

    A = np.array(sorted([int(i) for i in input().split()]))



    left = 0

    right = A[-1] * 2 + 5

    while right - left > 1:

        x = (left + right) // 2



        count = N**2 - np.searchsorted(A, x-A).sum()



        if count >= M:

            left = x

        else:

            right = x



    bound = np.searchsorted(A, left-A)

    count = N**2 - bound.sum()

    diff = count - M

    ans = ((N - bound) * A * 2).sum() - diff * left



    print(ans)





if __name__ == "__main__":

    main()

######################
# AC: ms(PyPy)
# AC: ms(Python3)
######################
from bisect import bisect_left
import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    A = [int(i) for i in input().split()]
    A.sort()
    left = 0
    right = A[-1] * 2 + 5
    while right - left > 1:
        X = (left + right) // 2
        count = 0
        for a in A:
            i = bisect_left(A, X - a)
            count += N - i
        if count >= M:
            left = X
        else:
            right = X
    count = 0
    num = []
    append = num.append
    for a in A:
        i = bisect_left(A, left - a)
        count += N - i
        append(N - i)
    diff = count - M
    ans = 0
    for i, a in zip(num, A):
        ans += i * a
    print((ans * 2 - diff * left))


if __name__ == "__main__":
    main()

import numpy as np
import sys

input = sys.stdin.readline


def main():
    N, M = list(map(int, input().split()))
    A = np.array(sorted([int(i) for i in input().split()]))
    left = 0
    right = A[-1] * 2 + 5
    while right - left > 1:
        x = (left + right) // 2
        count = N**2 - np.searchsorted(A, x - A).sum()
        if count >= M:
            left = x
        else:
            right = x
    bound = np.searchsorted(A, left - A)
    count = N**2 - bound.sum()
    diff = count - M
    ans = ((N - bound) * A * 2).sum() - diff * left
    print(ans)


if __name__ == "__main__":
    main()

-###################### -# AC: ms(PyPy) -# AC: ms(Python3) -###################### -from bisect import bisect_left +import numpy as np -    A = [int(i) for i in input().split()] -    A.sort() +    A = np.array(sorted([int(i) for i in input().split()])) -        X = (left + right) // 2 -        count = 0 -        for a in A: -            i = bisect_left(A, X - a) -            count += N - i +        x = (left + right) // 2 +        count = N**2 - np.searchsorted(A, x - A).sum() -            left = X +            left = x -            right = X -    count = 0 -    num = [] -    append = num.append -    for a in A: -        i = bisect_left(A, left - a) -        count += N - i -        append(N - i) +            right = x +    bound = np.searchsorted(A, left - A) +    count = N**2 - bound.sum() -    ans = 0 -    for i, a in zip(num, A): -        ans += i * a -    print((ans * 2 - diff * left)) +    ans = ((N - bound) * A * 2).sum() - diff * left +    print(ans)