from numpy.fft import rfft, irfft

import numpy as np



import sys

input = sys.stdin.readline



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

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



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

for a in A:

    C[a] += 1



L = 2*10**5+4



CC = rfft(np.array(C), L)

X = (irfft(CC*CC)+0.5).astype(int)

count = 0

ans = 0

for i in reversed(list(range(L))):

    x = X[i]

    if count + x >= M:

        ans += i*(M-count)

        break

    ans += i*x

    count += x



print(ans)
import sys

input = sys.stdin.readline



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

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



A.sort(reverse=True)

l = 0

r = 3*10**5

while r - l > 1:

    m = (r + l)//2 # 和がm以上になるペアはいくつ？

    ind = N-1

    cnt = 0

    for a in A:

        while ind >= 0 and A[ind] + a < m:

            ind -= 1

        cnt += ind+1

    if cnt >= M:

        l = m

    else:

        r = m



B = [0]

for a in A:

    B.append(B[-1]+a)



ans = 0

border = l

ind = N-1

cnt = 0

for a in A:

    while ind >= 0 and A[ind] + a < border:

        ind -= 1

    cnt += (ind+1)

    ans += a*(ind+1) + B[ind+1]



ans -= (cnt-M)*border



print(ans)
from numpy.fft import rfft, irfft
import numpy as np
import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
C = [0] * (10**5 + 1)
for a in A:
    C[a] += 1
L = 2 * 10**5 + 4
CC = rfft(np.array(C), L)
X = (irfft(CC * CC) + 0.5).astype(int)
count = 0
ans = 0
for i in reversed(list(range(L))):
    x = X[i]
    if count + x >= M:
        ans += i * (M - count)
        break
    ans += i * x
    count += x
print(ans)

import sys

input = sys.stdin.readline
N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort(reverse=True)
l = 0
r = 3 * 10**5
while r - l > 1:
    m = (r + l) // 2  # 和がm以上になるペアはいくつ？
    ind = N - 1
    cnt = 0
    for a in A:
        while ind >= 0 and A[ind] + a < m:
            ind -= 1
        cnt += ind + 1
    if cnt >= M:
        l = m
    else:
        r = m
B = [0]
for a in A:
    B.append(B[-1] + a)
ans = 0
border = l
ind = N - 1
cnt = 0
for a in A:
    while ind >= 0 and A[ind] + a < border:
        ind -= 1
    cnt += ind + 1
    ans += a * (ind + 1) + B[ind + 1]
ans -= (cnt - M) * border
print(ans)

-from numpy.fft import rfft, irfft -import numpy as np -C = [0] * (10**5 + 1) +A.sort(reverse=True) +l = 0 +r = 3 * 10**5 +while r - l > 1: +    m = (r + l) // 2  # 和がm以上になるペアはいくつ？ +    ind = N - 1 +    cnt = 0 +    for a in A: +        while ind >= 0 and A[ind] + a < m: +            ind -= 1 +        cnt += ind + 1 +    if cnt >= M: +        l = m +    else: +        r = m +B = [0] -    C[a] += 1 -L = 2 * 10**5 + 4 -CC = rfft(np.array(C), L) -X = (irfft(CC * CC) + 0.5).astype(int) -count = 0 +    B.append(B[-1] + a) -for i in reversed(list(range(L))): -    x = X[i] -    if count + x >= M: -        ans += i * (M - count) -        break -    ans += i * x -    count += x +border = l +ind = N - 1 +cnt = 0 +for a in A: +    while ind >= 0 and A[ind] + a < border: +        ind -= 1 +    cnt += ind + 1 +    ans += a * (ind + 1) + B[ind + 1] +ans -= (cnt - M) * border