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)
n, m = list(map(int, input().split()))

a = [int(x) for x in input().split()]



aa = [0]*(10**5+1)

aa_sum = [0]*(10**5+1)



for x in a:

    aa[x] += 1

    aa_sum[x] += x



for i in range(10**5)[::-1]:

    aa[i] = aa[i] + aa[i+1]

    aa_sum[i] = aa_sum[i] + aa_sum[i+1]





def count(x):

    cnt = 0

    sm = 0

    for i in range(n):

        if x-a[i] < 0:

            cnt += n

            sm += aa_sum[0]+n*a[i]

        elif x-a[i] > 10**5:

            continue

        else:

            cnt += aa[x-a[i]]

            sm += aa_sum[x-a[i]]+aa[x-a[i]]*a[i]



    return cnt, sm





bottom = 0

top = 10**6



while top - bottom > 1:

    mid = (top+bottom) // 2

    cnt, sm = count(mid)

    if cnt < m:

        top = mid

    else:

        bottom = mid



cnt, sm = count(bottom)

ans = sm - (cnt-m)*bottom



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)

n, m = list(map(int, input().split()))
a = [int(x) for x in input().split()]
aa = [0] * (10**5 + 1)
aa_sum = [0] * (10**5 + 1)
for x in a:
    aa[x] += 1
    aa_sum[x] += x
for i in range(10**5)[::-1]:
    aa[i] = aa[i] + aa[i + 1]
    aa_sum[i] = aa_sum[i] + aa_sum[i + 1]


def count(x):
    cnt = 0
    sm = 0
    for i in range(n):
        if x - a[i] < 0:
            cnt += n
            sm += aa_sum[0] + n * a[i]
        elif x - a[i] > 10**5:
            continue
        else:
            cnt += aa[x - a[i]]
            sm += aa_sum[x - a[i]] + aa[x - a[i]] * a[i]
    return cnt, sm


bottom = 0
top = 10**6
while top - bottom > 1:
    mid = (top + bottom) // 2
    cnt, sm = count(mid)
    if cnt < m:
        top = mid
    else:
        bottom = mid
cnt, sm = count(bottom)
ans = sm - (cnt - m) * bottom
print(ans)

-from bisect import bisect_left -from bisect import bisect_right - -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] +a = [int(x) for x in input().split()] +aa = [0] * (10**5 + 1) +aa_sum = [0] * (10**5 + 1) +for x in a: +    aa[x] += 1 +    aa_sum[x] += x +for i in range(10**5)[::-1]: +    aa[i] = aa[i] + aa[i + 1] +    aa_sum[i] = aa_sum[i] + aa_sum[i + 1] -def chk(x): -    case = 0 +def count(x): +    cnt = 0 +    sm = 0 -        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 +        if x - a[i] < 0: +            cnt += n +            sm += aa_sum[0] + n * a[i] +        elif x - a[i] > 10**5: +            continue +        else: +            cnt += aa[x - a[i]] +            sm += aa_sum[x - a[i]] + aa[x - a[i]] * a[i] +    return cnt, sm -l = 2 * a[-1] + 1  # NG -r = 1  # OK -while abs(r - l) > 1: -    kk = (r + l) // 2 -    if chk(kk): -        r = kk +bottom = 0 +top = 10**6 +while top - bottom > 1: +    mid = (top + bottom) // 2 +    cnt, sm = count(mid) +    if cnt < m: +        top = mid -        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 +        bottom = mid +cnt, sm = count(bottom) +ans = sm - (cnt - m) * bottom