from bisect import bisect_left as bisect

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

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

A.sort()

def combination(X):

    res = 0

    for i in range(N):

        j = bisect(A,X-A[i])

        res += N-j

    return res

l = 0

r = 2*10**5+1

m = (l+r)//2

for i in range(20):

    c = combination(m)

    if c < M:

        r = m

    else:

        l = m

    m = (l+r)//2

    

if combination(m) >= M:

     m += 1



S = [0]*(N+1)

for i in range(N):

    S[i]=S[i-1]+A[i]



ans = 0

for i in range(N):

    j = bisect(A,m-A[i])

    ans += A[i]*(N-j)

    ans += S[N-1]-S[j-1]

ans += (M-combination(m))*(m-1)

print(ans)
import numpy as np

from numpy.fft import rfft,irfft

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

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

a = np.zeros(10**5+1)

for i in range(N):

    a[A[i]] += 1

b = rfft(a,2*10**5+1)

b = irfft(b*b,2*10**5+1)

b = np.rint(b).astype(np.int64)

c = 0

ans = 0

for n in range(2*10**5,1,-1):

    if c+b[n]<M:

        c += b[n]

        ans += b[n]*n

    else:

        ans += (M-c)*n

        c = M

        break

print(ans)
from bisect import bisect_left as bisect

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


def combination(X):
    res = 0
    for i in range(N):
        j = bisect(A, X - A[i])
        res += N - j
    return res


l = 0
r = 2 * 10**5 + 1
m = (l + r) // 2
for i in range(20):
    c = combination(m)
    if c < M:
        r = m
    else:
        l = m
    m = (l + r) // 2
if combination(m) >= M:
    m += 1
S = [0] * (N + 1)
for i in range(N):
    S[i] = S[i - 1] + A[i]
ans = 0
for i in range(N):
    j = bisect(A, m - A[i])
    ans += A[i] * (N - j)
    ans += S[N - 1] - S[j - 1]
ans += (M - combination(m)) * (m - 1)
print(ans)

import numpy as np
from numpy.fft import rfft, irfft

N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
a = np.zeros(10**5 + 1)
for i in range(N):
    a[A[i]] += 1
b = rfft(a, 2 * 10**5 + 1)
b = irfft(b * b, 2 * 10**5 + 1)
b = np.rint(b).astype(np.int64)
c = 0
ans = 0
for n in range(2 * 10**5, 1, -1):
    if c + b[n] < M:
        c += b[n]
        ans += b[n] * n
    else:
        ans += (M - c) * n
        c = M
        break
print(ans)

-from bisect import bisect_left as bisect +import numpy as np +from numpy.fft import rfft, irfft -A.sort() - - -def combination(X): -    res = 0 -    for i in range(N): -        j = bisect(A, X - A[i]) -        res += N - j -    return res - - -l = 0 -r = 2 * 10**5 + 1 -m = (l + r) // 2 -for i in range(20): -    c = combination(m) -    if c < M: -        r = m +a = np.zeros(10**5 + 1) +for i in range(N): +    a[A[i]] += 1 +b = rfft(a, 2 * 10**5 + 1) +b = irfft(b * b, 2 * 10**5 + 1) +b = np.rint(b).astype(np.int64) +c = 0 +ans = 0 +for n in range(2 * 10**5, 1, -1): +    if c + b[n] < M: +        c += b[n] +        ans += b[n] * n -        l = m -    m = (l + r) // 2 -if combination(m) >= M: -    m += 1 -S = [0] * (N + 1) -for i in range(N): -    S[i] = S[i - 1] + A[i] -ans = 0 -for i in range(N): -    j = bisect(A, m - A[i]) -    ans += A[i] * (N - j) -    ans += S[N - 1] - S[j - 1] -ans += (M - combination(m)) * (m - 1) +        ans += (M - c) * n +        c = M +        break