Language: C++

#include <bits/stdc++.h>
using namespace std;


#define _rep(n, a, b) for (ll n = (a); n <= (b); ++n)
#define _rev(n, a, b) for (ll n = (a); n >= (b); --n)
#define _for(n, a, b) for (ll n = (a); n < (b); ++n)
#define _rof(n, a, b) for (ll n = (a); n > (b); --n)
#define oo 0x3f3f3f3f3f3f
#define ll long long
#define db double
#define eps 1e-6
#define bin(x) cout << bitset<10>(x) << endl;
#define what_is(x) cerr << #x << " is " << x << endl
#define met(a, b) memset(a, b, sizeof(a))
#define mp(a, b) make_pair(a, b)
#define all(x) x.begin(), x.end()
#define pii pair<ll, ll>
#define pdd pair<db, db>
#define pi acos(-1.0)
const ll maxn = 1e6 + 10;

const ll N = 2e5 + 5;
ll n;
ll k;
vector<ll> neg, pos;
ll smaller_than(ll mid)
{
    mid++;
    ll ret = 0;
    ll neg_num = neg.size(), pos_num = pos.size();
    if (mid == 0)
    {
        for (ll i = 0; i < pos_num; i++)
            if (pos[i] == 0)
                ret += neg_num;
        ret += (ll)neg_num * (neg_num - 1) / 2;
        ret += (ll)pos_num * (pos_num - 1) / 2;
        ret = (ll)n * (n - 1) / 2 - ret;
       return ret;
    }
    if (mid > 0)
    {
        for (ll i = 0; i < neg_num - 1; i++)
        {
            ll x = mid / neg[i];
            if (mid % neg[i])
                x++;
            ll k = lower_bound(neg.begin() + i + 1, neg.end(), x) - neg.begin();
            ret += neg_num - k;
        }
        for (ll i = 0; i < pos_num - 1; i++)
        {
            if (pos[i] == 0)
                continue;
            ll x = mid / pos[i];
            if (mid % pos[i])
                x++;
            ll k = lower_bound(pos.begin() + i + 1, pos.end(), x) - pos.begin();
            ret += pos_num - k;
        }
        ret = (ll)n * (n - 1) / 2 - ret;
       return ret;
    }
    if (mid < 0)
    {
        mid *= -1;
        ret += (ll)neg_num * (neg_num - 1) / 2;
        ret += (ll)pos_num * (pos_num - 1) / 2;
        for (ll i = 0; i < neg_num; i++)
        {
            ll x = mid / neg[i];
            ll k = upper_bound(pos.begin(), pos.end(), x) - pos.begin() - 1;
            ret += k + 1;
        }
        ret = (ll)n * (n - 1) / 2 - ret;
       return ret;
    }
}
ll main()
{
    scanf("%lld%lld", &n, &k);
    for (ll i = 1; i <= n; i++)
    {
        ll x;
        scanf("%lld", &x);
        if (x < 0)
            neg.push_back(-x);
        else
            pos.push_back(x);
    }
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    ll l = -1e18, r = 1e18, ans;
    while (l <= r)
    {
        ll mid = l + r >> 1;
        if (smaller_than(mid) >= k)
            ans = mid, r = mid - 1;
        else
            l = mid + 1;
    }
    printf("%lld\n", ans);
}
// signed main()
// {
// 	cin >> n >> k;
// 	_rep(i, 1, n)
// 	{
// 		ll tmp;
// 		cin >> tmp;
// 		if (tmp < 0)
// 			neg.push_back(-tmp);
// 		else
// 			pos.push_back(tmp);
// 	}
// 	sort(all(pos));
// 	sort(all(neg));
// 	ll l = -1e18, r = 1e18, ans = 0;
// 	while (r > l)
// 	{
// 		ll mid = l + r >> 1;
// 		if (smaller_than(mid) >= k)
// 		{
// 			r = mid - 1;
// 			ans = mid;
// 		}
// 		else
// 		{
// 			l = mid + 1;
// 		}
// 	}
// 	cout << ans << endl;
// }

Compiler output:
cc1plus: error: '::main' must return 'int'
a.cc: In function 'long long int smaller_than(long long int)':
a.cc:79:1: warning: control reaches end of non-void function [-Wreturn-type]
   79 | }
      | ^