import sys

input = sys.stdin.readline

from bisect import *



def judge(x):

    cnt = 0

    

    for i in range(N):

        idx = bisect_left(A, x-A[i])

        cnt += N-idx

    

    return cnt>=M

    

def binary_search():

    l, r = 0, 10**11

    

    while l<=r:

        mid = (l+r)//2

        

        if judge(mid):

            l = mid+1

        else:

            r = mid-1

    

    return r



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

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

A.sort()

border = binary_search()

acc = [0]



for Ai in A:

    acc.append(acc[-1]+Ai)



ans = 0

cnt = 0



for i in range(N):

    idx = bisect_left(A, border-A[i]+1)

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

    cnt += N-idx



ans += (M-cnt)*border



print(ans)
import sys

input = sys.stdin.readline

from bisect import *



def judge(x):

    cnt = 0

    

    for Ai in A:

        cnt += N-bisect_left(A, x-Ai+1)

    

    return cnt<M



def binary_search():

    l, r = 0, 2*max(A)

    

    while l<=r:

        m = (l+r)//2

        

        if judge(m):

            r = m-1

        else:

            l = m+1

    

    return l



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

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

A.sort()

border = binary_search()

acc = [0]*(N+1)



for i in range(N):

    acc[i+1] = acc[i]+A[i]

    

cnt = 0

ans = 0



for Ai in A:

    j = bisect_left(A, border-Ai+1)

    cnt += N-j

    ans += (N-j)*Ai+acc[N]-acc[j]



ans += (M-cnt)*border

print(ans)
import sys

input = sys.stdin.readline
from bisect import *


def judge(x):
    cnt = 0
    for i in range(N):
        idx = bisect_left(A, x - A[i])
        cnt += N - idx
    return cnt >= M


def binary_search():
    l, r = 0, 10**11
    while l <= r:
        mid = (l + r) // 2
        if judge(mid):
            l = mid + 1
        else:
            r = mid - 1
    return r


N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
border = binary_search()
acc = [0]
for Ai in A:
    acc.append(acc[-1] + Ai)
ans = 0
cnt = 0
for i in range(N):
    idx = bisect_left(A, border - A[i] + 1)
    ans += A[i] * (N - idx) + acc[N] - acc[idx]
    cnt += N - idx
ans += (M - cnt) * border
print(ans)

import sys

input = sys.stdin.readline
from bisect import *


def judge(x):
    cnt = 0
    for Ai in A:
        cnt += N - bisect_left(A, x - Ai + 1)
    return cnt < M


def binary_search():
    l, r = 0, 2 * max(A)
    while l <= r:
        m = (l + r) // 2
        if judge(m):
            r = m - 1
        else:
            l = m + 1
    return l


N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
border = binary_search()
acc = [0] * (N + 1)
for i in range(N):
    acc[i + 1] = acc[i] + A[i]
cnt = 0
ans = 0
for Ai in A:
    j = bisect_left(A, border - Ai + 1)
    cnt += N - j
    ans += (N - j) * Ai + acc[N] - acc[j]
ans += (M - cnt) * border
print(ans)

-    for i in range(N): -        idx = bisect_left(A, x - A[i]) -        cnt += N - idx -    return cnt >= M +    for Ai in A: +        cnt += N - bisect_left(A, x - Ai + 1) +    return cnt < M -    l, r = 0, 10**11 +    l, r = 0, 2 * max(A) -        mid = (l + r) // 2 -        if judge(mid): -            l = mid + 1 +        m = (l + r) // 2 +        if judge(m): +            r = m - 1 -            r = mid - 1 -    return r +            l = m + 1 +    return l -acc = [0] +acc = [0] * (N + 1) +for i in range(N): +    acc[i + 1] = acc[i] + A[i] +cnt = 0 +ans = 0 -    acc.append(acc[-1] + Ai) -ans = 0 -cnt = 0 -for i in range(N): -    idx = bisect_left(A, border - A[i] + 1) -    ans += A[i] * (N - idx) + acc[N] - acc[idx] -    cnt += N - idx +    j = bisect_left(A, border - Ai + 1) +    cnt += N - j +    ans += (N - j) * Ai + acc[N] - acc[j]