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 numpy as np

def convolve(A, B):

    # 畳み込み  # 要素は整数

    # 3 つ以上の場合は一度にやった方がいい

    dtype = np.int64

    fft, ifft = np.fft.rfft, np.fft.irfft

    a, b = len(A), len(B)

    if a == b == 1:

        return np.array([A[0]*B[0]])

    n = a+b-1  # 返り値のリストの長さ

    k = 1 << (n-1).bit_length()

    AB = np.zeros((2, k), dtype=dtype)

    AB[0, :a] = A

    AB[1, :b] = B

    return np.rint(ifft(fft(AB[0]) * fft(AB[1]))).astype(np.int64)[:n]



import sys

input = sys.stdin.readline

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

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

 

cnt = np.zeros(100001)

for i in a:

    cnt[i] += 1 



c = convolve(cnt,cnt)

ans = 0

for i in range(len(c))[::-1]:

    if c[i] > 0:

      p = min(m,c[i])

      m -= p

      ans += i*p

      if m == 0:

        break

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 numpy as np


def convolve(A, B):
    # 畳み込み  # 要素は整数
    # 3 つ以上の場合は一度にやった方がいい
    dtype = np.int64
    fft, ifft = np.fft.rfft, np.fft.irfft
    a, b = len(A), len(B)
    if a == b == 1:
        return np.array([A[0] * B[0]])
    n = a + b - 1  # 返り値のリストの長さ
    k = 1 << (n - 1).bit_length()
    AB = np.zeros((2, k), dtype=dtype)
    AB[0, :a] = A
    AB[1, :b] = B
    return np.rint(ifft(fft(AB[0]) * fft(AB[1]))).astype(np.int64)[:n]


import sys

input = sys.stdin.readline
n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt = np.zeros(100001)
for i in a:
    cnt[i] += 1
c = convolve(cnt, cnt)
ans = 0
for i in range(len(c))[::-1]:
    if c[i] > 0:
        p = min(m, c[i])
        m -= p
        ans += i * p
        if m == 0:
            break
print(ans)

+import numpy as np + + +def convolve(A, B): +    # 畳み込み  # 要素は整数 +    # 3 つ以上の場合は一度にやった方がいい +    dtype = np.int64 +    fft, ifft = np.fft.rfft, np.fft.irfft +    a, b = len(A), len(B) +    if a == b == 1: +        return np.array([A[0] * B[0]]) +    n = a + b - 1  # 返り値のリストの長さ +    k = 1 << (n - 1).bit_length() +    AB = np.zeros((2, k), dtype=dtype) +    AB[0, :a] = A +    AB[1, :b] = B +    return np.rint(ifft(fft(AB[0]) * fft(AB[1]))).astype(np.int64)[:n] + + -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)] -] -a = [int(i) for i in input().split()] -b = [0] * 100001 +a = list(map(int, input().split())) +cnt = np.zeros(100001) -    b[i] += 1 -c = li(st(nu(b) * nu(b))) +    cnt[i] += 1 +c = convolve(cnt, cnt) -for i in range(200001)[::-1]: +for i in range(len(c))[::-1]: