from bisect import bisect_left

from bisect import bisect_right



n,m = list(map(int, input().split()))

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

a = sorted(a)



a_count = [0]*110000

a_sum = [0]*110000



for i in range(n):

    a_count[a[i]] += 1

    a_sum[a[i]] += a[i]



for i in range(100005,0,-1):

    a_count[i] += a_count[i+1]

    a_sum[i] += a_sum[i+1]



def chk(x):

    case = 0

    for i in range(n):

        case += n-bisect_right(a,x-a[i]-1)

    if case >= m:

        ch = True

    else:

        ch = False

    return ch





l = 2*a[-1]+1    #NG

r = 1 #OK



while abs(r-l) > 1:

    kk = (r+l)//2

    if chk(kk):

        r = kk

    else:

        l = kk



ans = 0

sm = sum(a)



l = r



case = 0

for i in range(n):

    num = n-bisect_right(a,l-a[i]-1)

    case += num

    ans += num*a[i]*2



ans -= (case-m)*l



print(ans)
from bisect import bisect_left

from bisect import bisect_right



n,m = list(map(int, input().split()))

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

a = sorted(a)



a_count = [0]*100010

a_sum = [0]*100010



for i in range(n):

    a_count[a[i]] += 1

    a_sum[a[i]] += a[i]



for i in range(100005,-1,-1):

    a_count[i] += a_count[i+1]

    a_sum[i] += a_sum[i+1]



def chk(x):

    case = 0

    for i in range(n):

        if 0<= x-a[i]<= 10**5+5:

            case += a_count[x-a[i]]

        elif x-a[i] < 0:

            case += n

    if case >= m:

        ch = True

    else:

        ch = False

    return ch



l = 2*a[-1]+1    #NG

r = 1 #OK



while abs(r-l) > 1:

    kk = (r+l)//2

    if chk(kk):

        r = kk

    else:

        l = kk



ans = 0

sm = sum(a)



l = r



case = 0

for i in range(n):

    num = n-bisect_right(a,l-a[i]-1)

    case += num

    ans += num*a[i]*2



ans -= (case-m)*l



print(ans)
from bisect import bisect_left
from bisect import bisect_right

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a_count = [0] * 110000
a_sum = [0] * 110000
for i in range(n):
    a_count[a[i]] += 1
    a_sum[a[i]] += a[i]
for i in range(100005, 0, -1):
    a_count[i] += a_count[i + 1]
    a_sum[i] += a_sum[i + 1]


def chk(x):
    case = 0
    for i in range(n):
        case += n - bisect_right(a, x - a[i] - 1)
    if case >= m:
        ch = True
    else:
        ch = False
    return ch


l = 2 * a[-1] + 1  # NG
r = 1  # OK
while abs(r - l) > 1:
    kk = (r + l) // 2
    if chk(kk):
        r = kk
    else:
        l = kk
ans = 0
sm = sum(a)
l = r
case = 0
for i in range(n):
    num = n - bisect_right(a, l - a[i] - 1)
    case += num
    ans += num * a[i] * 2
ans -= (case - m) * l
print(ans)

from bisect import bisect_left
from bisect import bisect_right

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
a_count = [0] * 100010
a_sum = [0] * 100010
for i in range(n):
    a_count[a[i]] += 1
    a_sum[a[i]] += a[i]
for i in range(100005, -1, -1):
    a_count[i] += a_count[i + 1]
    a_sum[i] += a_sum[i + 1]


def chk(x):
    case = 0
    for i in range(n):
        if 0 <= x - a[i] <= 10**5 + 5:
            case += a_count[x - a[i]]
        elif x - a[i] < 0:
            case += n
    if case >= m:
        ch = True
    else:
        ch = False
    return ch


l = 2 * a[-1] + 1  # NG
r = 1  # OK
while abs(r - l) > 1:
    kk = (r + l) // 2
    if chk(kk):
        r = kk
    else:
        l = kk
ans = 0
sm = sum(a)
l = r
case = 0
for i in range(n):
    num = n - bisect_right(a, l - a[i] - 1)
    case += num
    ans += num * a[i] * 2
ans -= (case - m) * l
print(ans)

-a_count = [0] * 110000 -a_sum = [0] * 110000 +a_count = [0] * 100010 +a_sum = [0] * 100010 -for i in range(100005, 0, -1): +for i in range(100005, -1, -1): -        case += n - bisect_right(a, x - a[i] - 1) +        if 0 <= x - a[i] <= 10**5 + 5: +            case += a_count[x - a[i]] +        elif x - a[i] < 0: +            case += n