#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cmath>
using namespace std;
using ll = long long;

class FMT {
public:
    static constexpr uint64_t W = 9713644485405565297ULL, P = (((1ULL << 32) - 1) << 32) + 1;

    static void init(int n) {
        if ((n & -n) != n || n < 1) throw;

        n_ = n;
        n_inv_ = P - P / n_;
        if (n_ < 4) return;

        w_.resize(n_ * 2);

        uint64_t w1 = W;
        for (int n = n_; n < 1 << 24; n *= 2) {
            w1 = mul(w1, w1);
        }

        for (int l = 0; l < 2; l++) {
            uint64_t *w = &w_[l * n_];
            w[0] = 1;
            for (int i = 1; i < n_ / 2; i++) {
                w[i] = mul(w[i - 1], w1);
            }
            for (int i = 0; i < n_ / 2; i++) {
                w[n_ / 2 + i] = w[i * 2];
            }
            w1 = mul(w_[n_ / 2 - 1], mul(w_[n_ / 4], w_[n_ / 4]));
        }
    }
    static int get_2(int n) {
        int r = 1;
        while (r < n) r *= 2;
        return r;
    }
    FMT() : data_(n_, 0) {}

    static uint64_t add(uint64_t a1, uint64_t a2) {
        const uint64_t t = a1 + a2;
        return (t >= a1 && t < P) ? t : t - P;
    }
    static uint64_t sub(uint64_t a1, uint64_t a2) {
        const uint64_t t = a1 - a2;
        return t <= a1 ? t : t + P;
    }
    static uint64_t mul(uint64_t a1, uint64_t a2) {
        __uint128_t t = (__uint128_t)a1 * a2;
        uint64_t x0 = (uint64_t)t;
        uint64_t x1 = x0 >> 32; x0 = (uint32_t)x0;
        uint64_t x2 = (uint64_t)(t >> 64);
        uint64_t x3 = x2 >> 32; x2 = (uint32_t)x2;
        uint64_t r = x0 - x3 - x2;
        if ((int64_t)r < 0) r += P;
        return add(r, add(x1 << 32, x2 << 32));
    }

    uint64_t &operator[](size_t i) {
        return data_[i];
    }
    void fmt(int sign) {
        if (n_ > 2) {
            if (sign > 0) {
                fmt_f(n_, &data_[0], &w_[0]);
            } else {
                fmt_t(n_, &data_[0], &w_[n_]);
            }
        } else if (n_ == 2) {
            fmt_2(&data_[0]);
        }
    }
    void conv(FMT &b) {
        fmt(+1);
        if (this != &b) b.fmt(+1);
        for (int i = 0; i < n_; i++) {
            data_[i] = mul(data_[i], b.data_[i]);
        }
        fmt(-1);
        for (int i = 0; i < n_; i++) {
            data_[i] = mul(data_[i], n_inv_);
        }
    }

private:
    static void fmt_f(int n, uint64_t *p, uint64_t *w) {
        const int m = n / 2;

        for (int i = 0; i < m; i++) {
            const int j = i + m;
            const uint64_t t0 = add(p[i], p[j]);
            const uint64_t t1 = mul(sub(p[i], p[j]), w[i]);
            p[i] = t0;
            p[j] = t1;
        }

        if (m == 2) {
            fmt_2(p);
            fmt_2(p + 2);
        } else {
            fmt_f(m, p, w + m);
            fmt_f(m, p + m, w + m);
        }
    }
    static void fmt_t(int n, uint64_t *p, uint64_t *w) {
        const int m = n / 2;

        if (m == 2) {
            fmt_2(p);
            fmt_2(p + 2);
        } else {
            fmt_t(m, p, w + m);
            fmt_t(m, p + m, w + m);
        }

        for (int i = 0; i < m; i++) {
            int j = i + m;
            const uint64_t t0 = mul(w[i], p[j]);
            p[j] = sub(p[i], t0);
            p[i] = add(p[i], t0);
        }
    }
    static void fmt_2(uint64_t *p) {
        const uint64_t t0 = add(p[0], p[1]);
        const uint64_t t1 = sub(p[0], p[1]);
        p[0] = t0;
        p[1] = t1;
    }

    static int n_;
    static uint64_t n_inv_;
    static vector<uint64_t> w_;
    vector<uint64_t> data_;
};

int FMT::n_;
uint64_t FMT::n_inv_;
vector<uint64_t> FMT::w_;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    ll m;
    cin >> n >> m;

    int k = FMT::get_2(100001 * 2);
    FMT::init(k);
    FMT x;

    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;

        x[a]++;
    }

    x.conv(x);

    ll r = 0, s = 0;
    for (int i = k - 1; i >= 0; i--) {
        r += (ll)x[i] * i;
        s += x[i];
        if (s >= m) {
            r -= (s - m) * i;
            break;
        }
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 6400