from bisect import bisect_left





def check(x, m):

    # 幸福度が x 以上となる握手が m 通り以上か

    cnt = 0

    for i in range(N):

        y = x - A[i]

        p = bisect_left(A, y)

        cnt += N - p

    return cnt >= m





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

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

A.sort()



S = [0] * (N + 1)

for i, a in enumerate(A):

    S[i + 1] = S[i] + a



ok = 0

ng = 2 * 10 ** 5 + 1

while abs(ok - ng) > 1:

    mid = (ok + ng) // 2

    if check(mid, M):

        ok = mid

    else:

        ng = mid



X = ok

ans = 0

cnt = 0

amari = 2 * 10 ** 5 + 1

for i in range(N):

    Aj = X - A[i]

    j = bisect_left(A, Aj)

    ans += S[N] - S[j] + A[i] * (N - j)

    cnt += N - j

    if j < N:

        amari = min(amari, A[i] + A[j])



print((ans - (cnt - M) * amari))

from bisect import bisect_left





def solve(m):

    r = N - 1

    l = 0

    cnt = 0

    while 0 <= r and l < N:

        if A[r] + A[l] < m:

            l += 1

        else:

            cnt += N - l

            r -= 1

    return cnt





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

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

A.sort()

S = [0] * (N + 1)

for i in range(N):

    S[i + 1] = S[i] + A[i]



# [ok, ng) - Maximum

# (ng, ok] - Minimum

# ok が 最終的な答え

ok = 0

ng = 10 ** 21

while abs(ok - ng) > 1:

    mid = (ok + ng) // 2

    cnt = solve(mid)

    if cnt >= M:

        ok = mid

    else:

        ng = mid



X = ok

amari = float('inf')

cnt = 0

score = 0

for i, Ai in enumerate(A):

    Aj = X - Ai

    j = bisect_left(A, Aj)

    score += S[N] - S[j] + Ai * (N - j)

    cnt += N - j

    if j < N:

        amari = min(amari, A[i] + A[j])



print((score - (cnt - M) * amari))

from bisect import bisect_left


def check(x, m):
    # 幸福度が x 以上となる握手が m 通り以上か
    cnt = 0
    for i in range(N):
        y = x - A[i]
        p = bisect_left(A, y)
        cnt += N - p
    return cnt >= m


N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
S = [0] * (N + 1)
for i, a in enumerate(A):
    S[i + 1] = S[i] + a
ok = 0
ng = 2 * 10**5 + 1
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if check(mid, M):
        ok = mid
    else:
        ng = mid
X = ok
ans = 0
cnt = 0
amari = 2 * 10**5 + 1
for i in range(N):
    Aj = X - A[i]
    j = bisect_left(A, Aj)
    ans += S[N] - S[j] + A[i] * (N - j)
    cnt += N - j
    if j < N:
        amari = min(amari, A[i] + A[j])
print((ans - (cnt - M) * amari))

from bisect import bisect_left


def solve(m):
    r = N - 1
    l = 0
    cnt = 0
    while 0 <= r and l < N:
        if A[r] + A[l] < m:
            l += 1
        else:
            cnt += N - l
            r -= 1
    return cnt


N, M = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
S = [0] * (N + 1)
for i in range(N):
    S[i + 1] = S[i] + A[i]
# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
ok = 0
ng = 10**21
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    cnt = solve(mid)
    if cnt >= M:
        ok = mid
    else:
        ng = mid
X = ok
amari = float("inf")
cnt = 0
score = 0
for i, Ai in enumerate(A):
    Aj = X - Ai
    j = bisect_left(A, Aj)
    score += S[N] - S[j] + Ai * (N - j)
    cnt += N - j
    if j < N:
        amari = min(amari, A[i] + A[j])
print((score - (cnt - M) * amari))

-def check(x, m): -    # 幸福度が x 以上となる握手が m 通り以上か +def solve(m): +    r = N - 1 +    l = 0 -    for i in range(N): -        y = x - A[i] -        p = bisect_left(A, y) -        cnt += N - p -    return cnt >= m +    while 0 <= r and l < N: +        if A[r] + A[l] < m: +            l += 1 +        else: +            cnt += N - l +            r -= 1 +    return cnt -for i, a in enumerate(A): -    S[i + 1] = S[i] + a +for i in range(N): +    S[i + 1] = S[i] + A[i] +# [ok, ng) - Maximum +# (ng, ok] - Minimum +# ok が 最終的な答え -ng = 2 * 10**5 + 1 +ng = 10**21 -    if check(mid, M): +    cnt = solve(mid) +    if cnt >= M: -ans = 0 +amari = float("inf") -amari = 2 * 10**5 + 1 -for i in range(N): -    Aj = X - A[i] +score = 0 +for i, Ai in enumerate(A): +    Aj = X - Ai -    ans += S[N] - S[j] + A[i] * (N - j) +    score += S[N] - S[j] + Ai * (N - j) -print((ans - (cnt - M) * amari)) +print((score - (cnt - M) * amari))