@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")
//@file:OptIn(ExperimentalStdlibApi::class)

import java.io.PrintWriter
import kotlin.math.*
import kotlin.random.Random
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
//    val startTime = System.nanoTime()

    val numCases = 1//readInt()
    case@ for(case in 1..numCases) {
//        print("Case #$case: ")

        val n = readInt()
        val m = readLong()
        val A = readIntArray(n)

        val amax = A.max()!!
        val fft = SuperFFT(amax+amax)
        val C = IntArray(amax+1)
        for(a in A) C[a]++

        val S = fft.sq(C)

        var ans = 0L
        var rem = m
        for(i in amax+amax downTo 0) {
            val k = min(rem, S[i])
            ans += k * i
            rem -= k
            if(rem == 0L) break
        }

        println(ans)
    }

//    iprintln("Time: ${(System.nanoTime() - startTime) / 1000000} ms")
}

inline val PRIMITIVE_ROOT get() = FftVal(3)
class SuperFFT(maxDeg: Int) {
    val n = getArrSize(maxDeg)
    private val ninv = FftVal(n).inv_unmemoized()

    fun getArrSize(deg: Int) = Integer.highestOneBit(deg shl 1 or 1)
    // prepares an array of suitable size for inPlace
    fun prepareUnsigned(arr: LongArray, deg: Int) = FftValArray(arr.copyOf(getArrSize(deg)))
    fun prepareSigned(arr: LongArray, deg: Int) = arr.toFftValArray(getArrSize(deg))
    fun prepare(arr: IntArray, deg: Int) =
        FftValArray(getArrSize(deg)).also { for(i in arr.indices) it[i] = arr[i].toFftVal() }

    // w[1] represents n-th root of unity e^(i * tau/n), w[k] = w[1]^k
    val w = PRIMITIVE_ROOT.pow(FFTTOTIENT / n).powArray(n-1)

    // rev[i] is reversal of bits in i
    private val rev = IntArray(n).also { rev ->
        var bit = 1
        var rbit = n shr 1
        while(bit < n) {
            for(i in 0 until bit) {
                rev[i or bit] = rbit or rev[i]
            }
            bit = bit shl 1
            rbit = rbit shr 1
        }
    }

    operator fun invoke(a: FftValArray, invert: Boolean): FftValArray {
        val res = a.copyOf(n)
        inPlace(res, invert)
        return res
    }

    // in-place FFT. Precondition: a.size <= n, and a.size is a power of 2
    fun inPlace(a: FftValArray, invert: Boolean) {
        val sz = a.size
        if(sz <= 1) return
        require(sz <= n && sz and -sz == sz) { "Array size $sz must be less than $n and a power of 2" }
        val st = n / sz
        for(i in 0 until sz) {
            val j = rev[i * st]
            if(i < j) a[i] = a[j].also { a[j] = a[i] }
        }

        var len = 2
        var ang = n shr 1 // = n / len, representing the angle tau / len
        if(invert) ang = -ang
        while(len <= sz) {
            var i = 0
            while(i < sz) {
                var k = 0
                val h = len shr 1
                for(j in i until i+h) {
                    val u = a[j]
                    val v = a[j+h] * w[k]
                    a[j] = u + v
                    a[j+h] = u - v
                    k = k + ang and n-1
                }
                i += len
            }

            len = len shl 1
            ang = ang shr 1
        }

        if(invert) {
            val szinv = ninv * st
            for(i in 0 until sz) a[i] *= szinv
        }
    }

    // mutates the arrays; b would be left in DFT form
    fun mulInPlace(a: FftValArray, b: FftValArray) {
        inPlace(a, false)
        inPlace(b, false)
        for(i in a.indices) a[i] *= b[i]
        inPlace(a, true)
    }

    fun mulUnsigned(a: LongArray, b: LongArray): LongArray {
        val deg = a.lastIndex + b.lastIndex
        require(deg < n) { "FFT capacity $n too small for polynomial of degree $deg" }
        val a1 = prepareUnsigned(a, deg)
        val b1 = prepareUnsigned(b, deg)
        mulInPlace(a1, b1)
        return a1.intArray//.copyOf(deg+1)
    }

    fun mulSigned(a: LongArray, b: LongArray): LongArray {
        val deg = a.lastIndex + b.lastIndex
        require(deg < n) { "FFT capacity $n too small for polynomial of degree $deg" }
        val a1 = prepareSigned(a, deg)
        val b1 = prepareSigned(b, deg)
        mulInPlace(a1, b1)
        val res = a1.intArray//.copyOf(deg+1)
        for(i in 0..deg) res[i] = FftVal(res[i]).toSigned()
        return res
    }

    fun mul(a: IntArray, b: IntArray): LongArray {
        val deg = a.lastIndex + b.lastIndex
        require(deg < n) { "FFT capacity $n too small for polynomial of degree $deg" }
        val a1 = prepare(a, deg)
        val b1 = prepare(b, deg)
        mulInPlace(a1, b1)
        val res = a1.intArray//.copyOf(deg+1)
        for(i in 0..deg) res[i] = FftVal(res[i]).toSigned()
        return res
    }

    fun sq(a: IntArray): LongArray {
        val deg = a.lastIndex * 2
        require(deg < n) { "FFT capacity $n too small for polynomial of degree $deg" }
        val a1 = prepare(a, deg)
        inPlace(a1, false)
        for(i in a1.indices) a1[i] *= a1[i]
        inPlace(a1, true)
        val res = a1.intArray//.copyOf(deg+1)
        for(i in 0..deg) res[i] = FftVal(res[i]).toSigned()
        return res
    }
}

infix fun Int.modulo(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }
infix fun Long.modulo(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }
infix fun Long.modulo(mod: Int) = modulo(mod.toLong()).toInt()

const val FFTMOD = 9223372036737335297
const val FFTBARR = -9223372036737335297 // Barrett reduction factor, floor(4^63 / MOD)
const val FFTTOTIENT = FFTMOD - 1

infix fun Long.uMulHigh(y: Long): Long { // gets high word of multiplication, treating as unsigned
    val x1 = this ushr 32
    val x2 = y ushr 32
    val y1 = this and 0xffff_ffff
    val y2 = y and 0xffff_ffff
    val z2 = x1 * x2
    val t = y1 * y2
    val z1 = (x1 + y1) * (x2 + y2)
    val z0 = z1 - z2 - t
    return ((t ushr 32) + z0 ushr 32) + z2
}

const val FFTBARR_H = FFTBARR ushr 32
const val FFTBARR_L = FFTBARR and 0xffff_ffff

fun Long.mulFftBarrHigh(): Long {
    val x1 = this ushr 32
    val y1 = this and 0xffff_ffff
    val z2 = x1 * FFTBARR_H
    val t = y1 * FFTBARR_L
    val z1 = (x1 + y1) * (FFTBARR_H + FFTBARR_L)
    val z0 = z1 - z2 - t
    return ((t ushr 32) + z0 ushr 32) + z2
}

fun Int.toFftVal() = toLong().toFftVal()
fun Long.toFftVal() = FftVal((this shr Long.SIZE_BITS - 1 and FFTMOD) + this) // assumes absolute value isn't greater than the huge modulus!

inline fun FftVal(int: Int) = FftVal(int.toLong())
inline class FftVal(val int: Long) {
    // normalizes an integer that's within range [-MOD, MOD) without branching
    private inline fun normalize(int: Long) =
        FftVal((int shr Long.SIZE_BITS - 1 and FFTMOD) + int)

    operator fun plus(other: FftVal) = normalize(int + other.int - FFTMOD)
    operator fun plus(other: Int) = plus(normalize(other.toLong()))
    operator fun inc() = normalize(int + (1 - FFTMOD))

    operator fun minus(other: FftVal) = normalize(int - other.int)
    operator fun minus(other: Int) = minus(normalize(other.toLong()))
    operator fun dec() = normalize(int - 1)
    operator fun unaryMinus() = normalize(-int)

    operator fun times(other: FftVal): FftVal {
        val xh = int uMulHigh other.int
        val xl = int * other.int

        val g = (xh.shl(2) or xl.ushr(62)).mulFftBarrHigh() + 1
        return normalize(xl - g * FFTMOD)
    }

    operator fun times(other: Int) = times(normalize(other.toLong()))

    fun pow(exponent: Long): FftVal {
        var e = if(exponent < 0) {
            require(int != 0L) { "Can't invert/divide by 0" }
            exponent modulo FFTMOD - 1
        } else exponent

        var res = FftVal(1)
        var b = this

        while(e > 0) {
            if(e and 1 == 1L) {
                res *= b
            }
            e = e shr 1
            b *= b
        }
        return res
    }
    fun pow(exponent: Int) = pow(exponent.toLong())

    inline fun inverse() = inv_unmemoized()

    fun inv_unmemoized(): FftVal {
        require(int != 0L) { "Can't invert/divide by 0" }
        return pow(FFTMOD - 2)
    }

    operator fun div(other: FftVal) = times(other.inverse())
    operator fun div(other: Int) = div(normalize(other.toLong()))

    fun toSigned() = if(int > FFTMOD shr 1) int - FFTMOD else int

    override inline fun toString() = int.toString()
}

inline class FftValArray(val intArray: LongArray): Collection<FftVal> {
    inline operator fun get(i: Int) = FftVal(intArray[i])
    inline operator fun set(i: Int, v: FftVal) { intArray[i] = v.int }

    override inline val size: Int get() = intArray.size
    inline val lastIndex get() = intArray.lastIndex
    inline val indices get() = intArray.indices

    override inline fun contains(element: FftVal): Boolean = element.int in intArray

    override fun containsAll(elements: Collection<FftVal>): Boolean = elements.all(::contains)

    override inline fun isEmpty(): Boolean = intArray.isEmpty()

    override fun iterator(): Iterator<FftVal> = object: Iterator<FftVal> {
        var index = 0
        override fun hasNext(): Boolean = index < size
        override fun next(): FftVal = get(index++)
    }

    fun copyOf(newSize: Int) = FftValArray(intArray.copyOf(newSize))
    fun copyOf() = copyOf(size)
}
fun FftValArray.copyInto(destination: FftValArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
    FftValArray(
        intArray.copyInto(
            destination.intArray,
            destinationOffset,
            startIndex,
            endIndex
        )
    )
inline fun FftValArray(size: Int) = FftValArray(LongArray(size))
inline fun FftValArray(size: Int, init: (Int) -> FftVal) =
    FftValArray(LongArray(size) { init(it).int })
fun LongArray.toFftValArray(newSize: Int = size): FftValArray {
    val new = copyOf(newSize)
    for(i in 0 until minOf(size, newSize)) new[i] = new[i].toFftVal().int
    return FftValArray(new)
}

fun FftVal.powArray(n: Int): FftValArray {
    val res = FftValArray(n + 1)
    res[0] = FftVal(1)
    for(i in 1..n) res[i] = res[i-1] * this
    return res
}

inline fun FftValArray.first() = get(0)
inline fun FftValArray.last() = get(lastIndex)

/** IO */
//@JvmField val INPUT = File("input.txt").inputStream()
//@JvmField val OUTPUT = File("output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar()
        else c
    }
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(c != '\n' && c != Char.MIN_VALUE) {
            append(c)
            c = readChar()
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/** shuffles and sort overrides to avoid quicksort attacks */
private inline fun <T> _shuffle(rnd: Random, get: (Int) -> T, set: (Int, T) -> Unit, size: Int) {
    // Fisher-Yates shuffle algorithm
    for (i in size - 1 downTo 1) {
        val j = rnd.nextInt(i + 1)
        val temp = get(i)
        set(i, get(j))
        set(j, temp)
    }
}

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

fun IntArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun IntArray.sort() { shuffle(); _sort() }
fun IntArray.sortDescending() { shuffle(); _sortDescending() }

fun LongArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun LongArray.sort() { shuffle(); _sort() }
fun LongArray.sortDescending() { shuffle(); _sortDescending() }

fun DoubleArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
fun DoubleArray.sort() { shuffle(); _sort() }
fun DoubleArray.sortDescending() { shuffle(); _sortDescending() }

fun CharArray.shuffle(rnd: Random = random) = _shuffle(rnd, ::get, ::set, size)
inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T: Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T: Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T: Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T: Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

fun `please stop removing these imports IntelliJ`() { iprintln(max(1, 2)) }

/** additional commons */
inline fun <T> Iterable<T>.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }
inline fun <T> Sequence<T>.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }
inline fun <T> Array<T>.sumByLong(func: (T) -> Long) = fold(0L) { acc, t -> acc + func(t) }
fun IntArray.sumLong() = fold(0L, Long::plus)

Measured memory_bytes: 57396