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

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

for i in range(n):a[i]*=-1

a.sort()

from bisect import bisect_left,bisect_right

def check(mid):

  mm=0

  for i in range(n):

    if -(a[i]+a[0])<mid:break

    mm+=bisect_right(a,-(mid+a[i]))

  return mm

ok=0

ng=10**10+7

while ng!=ok+1:

  mid=(ok+ng)//2

  if check(mid)>=m:ok=mid

  else:ng=mid

b=[0]

for i in a:b.append(b[-1]+i)

ans=0

for i in range(n):

  if -(a[i]+a[0])<ok:break

  ind=bisect_right(a,-(ok+a[i]))

  ans+=a[i]*ind

  ans+=b[ind]

print((-(ans+(check(ok)-m)*ok)))
from bisect import bisect_right as br

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

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

for i in range(n):a[i]*=-1

a.sort()

b=[0]

for i in a:b.append(b[-1]+i)

ng=2*10**5+7

ok=-1

while ok+1!=ng:

  mid=(ng+ok)//2

  co=0

  for i in a:co+=br(a,-(mid+i))

  if co<m:ng=mid

  else:ok=mid

ans=0

co=0

for i in a:

  ind=br(a,-(ok+i)-1)

  co+=ind

  ans+=-b[ind]-i*ind

ans+=(m-co)*ok

print(ans)
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
a.sort()
from bisect import bisect_left, bisect_right


def check(mid):
    mm = 0
    for i in range(n):
        if -(a[i] + a[0]) < mid:
            break
        mm += bisect_right(a, -(mid + a[i]))
    return mm


ok = 0
ng = 10**10 + 7
while ng != ok + 1:
    mid = (ok + ng) // 2
    if check(mid) >= m:
        ok = mid
    else:
        ng = mid
b = [0]
for i in a:
    b.append(b[-1] + i)
ans = 0
for i in range(n):
    if -(a[i] + a[0]) < ok:
        break
    ind = bisect_right(a, -(ok + a[i]))
    ans += a[i] * ind
    ans += b[ind]
print((-(ans + (check(ok) - m) * ok)))

from bisect import bisect_right as br

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
    a[i] *= -1
a.sort()
b = [0]
for i in a:
    b.append(b[-1] + i)
ng = 2 * 10**5 + 7
ok = -1
while ok + 1 != ng:
    mid = (ng + ok) // 2
    co = 0
    for i in a:
        co += br(a, -(mid + i))
    if co < m:
        ng = mid
    else:
        ok = mid
ans = 0
co = 0
for i in a:
    ind = br(a, -(ok + i) - 1)
    co += ind
    ans += -b[ind] - i * ind
ans += (m - co) * ok
print(ans)

+from bisect import bisect_right as br + -from bisect import bisect_left, bisect_right - - -def check(mid): -    mm = 0 -    for i in range(n): -        if -(a[i] + a[0]) < mid: -            break -        mm += bisect_right(a, -(mid + a[i])) -    return mm - - -ok = 0 -ng = 10**10 + 7 -while ng != ok + 1: -    mid = (ok + ng) // 2 -    if check(mid) >= m: -        ok = mid -    else: -        ng = mid +ng = 2 * 10**5 + 7 +ok = -1 +while ok + 1 != ng: +    mid = (ng + ok) // 2 +    co = 0 +    for i in a: +        co += br(a, -(mid + i)) +    if co < m: +        ng = mid +    else: +        ok = mid -for i in range(n): -    if -(a[i] + a[0]) < ok: -        break -    ind = bisect_right(a, -(ok + a[i])) -    ans += a[i] * ind -    ans += b[ind] -print((-(ans + (check(ok) - m) * ok))) +co = 0 +for i in a: +    ind = br(a, -(ok + i) - 1) +    co += ind +    ans += -b[ind] - i * ind +ans += (m - co) * ok +print(ans)