Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int 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 (int 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 (int i = 0; i < neg_num - 1; i++)
        {
            ll x = mid / neg[i];
            if (mid % neg[i])
                x++;
            int k = lower_bound(neg.begin() + i + 1, neg.end(), x) - neg.begin();
            ret += neg_num - k;
        }
        for (int i = 0; i < pos_num - 1; i++)
        {
            if (pos[i] == 0)
                continue;
            ll x = mid / pos[i];
            if (mid % pos[i])
                x++;
            int 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 (int i = 0; i < neg_num; i++)
        {
            ll x = mid / neg[i];
            int k = upper_bound(pos.begin(), pos.end(), x) - pos.begin() - 1;
            ret += k + 1;
        }
        ret = (ll)n * (n - 1) / 2 - ret;
       return ret;
    }
}
// int main()
// {
//     scanf("%d%lld", &n, &k);
//     for (int i = 1; i <= n; i++)
//     {
//         int x;
//         scanf("%d", &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:
a.cc: In function 'int main()':
a.cc:89:14: error: 'i' was not declared in this scope
   89 |         _rep(i, 1, n)
      |              ^
a.cc:89:9: error: '_rep' was not declared in this scope
   89 |         _rep(i, 1, n)
      |         ^~~~
a.cc:98:14: error: 'all' was not declared in this scope; did you mean 'std::filesystem::perms::all'?
   98 |         sort(all(pos));
      |              ^~~
      |              std::filesystem::perms::all
In file included from /usr/include/c++/14/filesystem:51,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200,
                 from a.cc:1:
/usr/include/c++/14/bits/fs_fwd.h:158:7: note: 'std::filesystem::perms::all' declared here
  158 |       all               =  0777,
      |       ^~~
a.cc: In function 'll smaller_than(ll)':
a.cc:60:1: warning: control reaches end of non-void function [-Wreturn-type]
   60 | }
      | ^