#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;

    FMT() : data_(n_, 0) {}

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

        n_ = n;
        if (n_ < 4) return;

        w0_.resize(n_ * 2);
        w_ = &w0_[0];
        w_[0] = 1;
        w_[1] = W;
        for (int n = n_; n < 1 << 24; n *= 2) {
            w_[1] = mul(w_[1], w_[1]);
        }
        for (int i = 2; i < n_ / 2; i++) {
            w_[i] = mul(w_[i - 1], w_[1]);
        }
        uint64_t *w = w_, *w1 = w_ + n_ / 2;
        for (int j = n_ / 4; j != 0; j /= 2) {
            for (int i = 0; i < j; i++) {
                *w1 = *w;
                w += 2;
                w1 += 1;
            }
        }
        const uint64_t r2 = mul(w_[n_ / 4], w_[n_ / 4]);
        w = w_;
        for (int j = n_ / 2; j != 0; j /= 2) {
            w[n_] = 1;
            for (int i = 1; i < j; i++) {
                w[j - i + n_] = mul(w[i], r2);
            }
            w += j;
        }
    }

    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) {
        return (__uint128_t)a1 * a2 % P;
    }
    static uint64_t n_inv() {
        return P - P / n_;
    }
    static int get_2(int n) {
        int r = 1;
        while (r < n) r *= 2;
        return r;
    }

    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_);
            } 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);
        const uint64_t t = n_inv();
        for (int i = 0; i < n_; i++) {
            data_[i] = mul(data_[i], t);
        }
    }

private:
    static int n_;
    static vector<uint64_t> w0_;
    static uint64_t *w_;
    vector<uint64_t> data_;

    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;
    }
};

int FMT::n_;
vector<uint64_t> FMT::w0_;
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