Language: C++

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>
#include <cmath>
#define N 200005
using namespace std;

typedef long long ll;
ll n, k, mx, s0, s1, s2, ans, l, r, md;
map<ll, ll> c1, c2;
vector<ll> a1, a2;

ll f12(ll p) {
	ll re = 0, i, j;
	j = 0;
	for (i = 0; i < s1; i++) {
		for (; j < s2; j++) {
			if (a1[i] * a2[j] <= p) break;
		}
		re += (s2 - j);
	}
	return re;
}

ll com(ll p) {return p * (p - 1) / 2;}
ll f1(ll p) {
	ll re = 0, i, j, cut = 2e9, sq = sqrt(p);
	if (sq * sq == p) {
		re += com(c1[sq]);
		cut = sq;
	}
	j = s1 - 1;
	for (i =0; i < s1 && a1[i] != cut; i++) {
		for (; j > i && a1[j] != cut; j--) {
			if (a1[i] * a1[j] <= p) break;
		}
		re += max((j - i), 0ll);
	}
	return re;
}

ll f2(ll p) {
	ll re = 0, i, j, cut = 2e9, sq = sqrt(p);
	if (sq * sq == p) {
		re += com(c2[sq]);
		cut = sq;
	}
	j = s2 - 1;
	for (i =0; i < s2 && a2[i] != cut; i++) {
		for (; j > i && a2[j] != cut; j--) {
			if (a2[i] * a2[j] <= p) break;
		}
		re += max((j - i), 0ll);
	}
	return re;
}

int main()
{
	ll i, t, cnt;
//	freopen ("input.txt", "r", stdin);
	cin >> n >> k;
	for (i = 0; i < n; i++) {
		scanf ("%lld", &t);
		if (t < 0) {
			a1.push_back(t);
			c1[-t]++;
		} else if (t == 0) {
			s0++;
		} else {
			c2[t]++;
			a2.push_back(t);
		}
	}
	s1 = a1.size();
	s2 = a2.size();
	if (!a1.empty()) sort(a1.begin(), a1.end());
	if (!a2.empty()) sort(a2.begin(), a2.end());
	l = -1e18;
	r = 1e18 + 1;
	while (r - l > 2) {
		md = (l + r) / 2;
		cnt = 0;
		if (md < 0) cnt += f12(md);
		else {
			cnt += s1 * s2;
			cnt += s0 * (s0 - 1) / 2;
			cnt += (s0) * (s1 + s2);
			if (md > 0) cnt += f1(md);
			if (md > 0) cnt += f2(md);
		}
		if (cnt >= k) {ans = md; r = md;}
		else l = md + 1;
	}
	for (i = r - 1; i >= l; i--) {
		md = i;
		cnt = 0;
		if (md < 0) cnt += f12(md);
		else {
			cnt += s1 * s2;
			cnt += s0 * (s0 - 1) / 2;
			cnt += (s0) * (s1 + s2);
			if (md > 0) cnt += f1(md);
			if (md > 0) cnt += f2(md);
		}
		if (cnt >= k) ans = md;
	}
	cout << ans << endl;
    return 0;
}


Compiler output:
a.cc:12:1: error: 'vector' does not name a type
   12 | vector<ll> a1, a2;
      | ^~~~~~
a.cc: In function 'll f12(ll)':
a.cc:19:29: error: 'a1' was not declared in this scope; did you mean 'y1'?
   19 |                         if (a1[i] * a2[j] <= p) break;
      |                             ^~
      |                             y1
a.cc:19:37: error: 'a2' was not declared in this scope; did you mean 's2'?
   19 |                         if (a1[i] * a2[j] <= p) break;
      |                                     ^~
      |                                     s2
a.cc: In function 'll f1(ll)':
a.cc:34:30: error: 'a1' was not declared in this scope; did you mean 'y1'?
   34 |         for (i =0; i < s1 && a1[i] != cut; i++) {
      |                              ^~
      |                              y1
a.cc: In function 'll f2(ll)':
a.cc:50:30: error: 'a2' was not declared in this scope; did you mean 's2'?
   50 |         for (i =0; i < s2 && a2[i] != cut; i++) {
      |                              ^~
      |                              s2
a.cc: In function 'int main()':
a.cc:67:25: error: 'a1' was not declared in this scope; did you mean 'y1'?
   67 |                         a1.push_back(t);
      |                         ^~
      |                         y1
a.cc:73:25: error: 'a2' was not declared in this scope; did you mean 's2'?
   73 |                         a2.push_back(t);
      |                         ^~
      |                         s2
a.cc:76:14: error: 'a1' was not declared in this scope; did you mean 'y1'?
   76 |         s1 = a1.size();
      |              ^~
      |              y1
a.cc:77:14: error: 'a2' was not declared in this scope; did you mean 's2'?
   77 |         s2 = a2.size();
      |              ^~
      |              s2