import sys

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

from bisect import bisect_left



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

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



b = [0]*(n+1)

a.sort()

for i in range(n):

  b[i+1] = b[i]+a[i]



def is_ok(arg):

    c = 0

    f = False

    for i in a:

      if c >= m:

        break

      c += (n-bisect_left(a,arg-i))

    if c >= m:

      f = True

    return f



def bisect_ok(ng, ok):

    while (abs(ok - ng) > 1):

        mid = (ok + ng) // 2

        if is_ok(mid):

            ok = mid

        else:

            ng = mid

    return ok



x = bisect_ok(2*a[-1]+1,1)

ans = 0

cnt = 0

for i in a:

  ind = n-bisect_left(a,x-i)

  cnt += ind

  ans += i*ind+(b[-1]-b[n-ind])

if cnt > m:

  ans -= x*(cnt-m)

print(ans)
import sys

input = sys.stdin.readline



mm = 10**10

k = mm.bit_length()

K = 1<<k

nu = lambda L: int("".join([bin(K+a)[-k:] for a in L[::-1]]), 2)

st = lambda n: bin(n)[2:] + "0"

li = lambda s: [int(a, 2) if len(a) else 0 for a in [s[-(i+1)*k-1:-i*k-1] for i in range(200001)]]



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

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

b = [0]*100001



for i in a:

    b[i] += 1

    

c = li(st(nu(b)*nu(b)))

ans = 0

for i in range(200001)[::-1]:

    if c[i] > 0:

      p = min(m,c[i])

      m -= p

      ans += i*p

      if m == 0:

        break

print(ans)
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
from bisect import bisect_left

n, m = list(map(int, readline().split()))
a = list(map(int, readline().split()))
b = [0] * (n + 1)
a.sort()
for i in range(n):
    b[i + 1] = b[i] + a[i]


def is_ok(arg):
    c = 0
    f = False
    for i in a:
        if c >= m:
            break
        c += n - bisect_left(a, arg - i)
    if c >= m:
        f = True
    return f


def bisect_ok(ng, ok):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


x = bisect_ok(2 * a[-1] + 1, 1)
ans = 0
cnt = 0
for i in a:
    ind = n - bisect_left(a, x - i)
    cnt += ind
    ans += i * ind + (b[-1] - b[n - ind])
if cnt > m:
    ans -= x * (cnt - m)
print(ans)

import sys

input = sys.stdin.readline
mm = 10**10
k = mm.bit_length()
K = 1 << k
nu = lambda L: int("".join([bin(K + a)[-k:] for a in L[::-1]]), 2)
st = lambda n: bin(n)[2:] + "0"
li = lambda s: [
    int(a, 2) if len(a) else 0
    for a in [s[-(i + 1) * k - 1 : -i * k - 1] for i in range(200001)]
]
n, m = list(map(int, input().split()))
a = [int(i) for i in input().split()]
b = [0] * 100001
for i in a:
    b[i] += 1
c = li(st(nu(b) * nu(b)))
ans = 0
for i in range(200001)[::-1]:
    if c[i] > 0:
        p = min(m, c[i])
        m -= p
        ans += i * p
        if m == 0:
            break
print(ans)

-read = sys.stdin.buffer.read -readline = sys.stdin.buffer.readline -readlines = sys.stdin.buffer.readlines -from bisect import bisect_left - -n, m = list(map(int, readline().split())) -a = list(map(int, readline().split())) -b = [0] * (n + 1) -a.sort() -for i in range(n): -    b[i + 1] = b[i] + a[i] - - -def is_ok(arg): -    c = 0 -    f = False -    for i in a: -        if c >= m: +input = sys.stdin.readline +mm = 10**10 +k = mm.bit_length() +K = 1 << k +nu = lambda L: int("".join([bin(K + a)[-k:] for a in L[::-1]]), 2) +st = lambda n: bin(n)[2:] + "0" +li = lambda s: [ +    int(a, 2) if len(a) else 0 +    for a in [s[-(i + 1) * k - 1 : -i * k - 1] for i in range(200001)] +] +n, m = list(map(int, input().split())) +a = [int(i) for i in input().split()] +b = [0] * 100001 +for i in a: +    b[i] += 1 +c = li(st(nu(b) * nu(b))) +ans = 0 +for i in range(200001)[::-1]: +    if c[i] > 0: +        p = min(m, c[i]) +        m -= p +        ans += i * p +        if m == 0: -        c += n - bisect_left(a, arg - i) -    if c >= m: -        f = True -    return f - - -def bisect_ok(ng, ok): -    while abs(ok - ng) > 1: -        mid = (ok + ng) // 2 -        if is_ok(mid): -            ok = mid -        else: -            ng = mid -    return ok - - -x = bisect_ok(2 * a[-1] + 1, 1) -ans = 0 -cnt = 0 -for i in a: -    ind = n - bisect_left(a, x - i) -    cnt += ind -    ans += i * ind + (b[-1] - b[n - ind]) -if cnt > m: -    ans -= x * (cnt - m)