Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	lint K;
	cin >> K;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];
	sort(A.begin(), A.end());


	auto judge = [&](auto idx) {

		int cnt = 0;

		for (int i = 0; i < N; i++) {
			if (A[i] == 0) { if (idx >= 0) cnt += N - i - 1; }
			else if (A[i] < 0) cnt += A.end() - lower_bound(A.begin() + i + 1, A.end(), idx / A[i]);
			else cnt += max(upper_bound(A.begin(), A.end(), idx / A[i]) - (A.begin() + i + 1), 0LL);
		}

		return cnt >= K;
	};

	auto binary_search = [&](auto f) {

		auto ng = -LINF;
		auto ok =  LINF;

		while (abs(ok - ng) > 1) {
			auto mid = (ok + ng) / 2;

			if (f(mid)) ok = mid;
			else ng = mid;
		}

		return ok;
	};

	lint ans = binary_search(judge);
	if (ans < 0) ans++;

	cout << ans << "\n";

	return 0;
}

Compiler output:
a.cc: In instantiation of 'main()::<lambda(auto:1)> [with auto:1 = long long int]':
a.cc:75:9:   required from 'main()::<lambda(auto:2)> [with auto:2 = main()::<lambda(auto:1)>]'
   75 |                         if (f(mid)) ok = mid;
      |                             ~^~~~~
a.cc:82:26:   required from here
   82 |         lint ans = binary_search(judge);
      |                    ~~~~~~~~~~~~~^~~~~~~
a.cc:61:40: error: no matching function for call to 'max(__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type, long long int)'
   61 |                         else cnt += max(upper_bound(A.begin(), A.end(), idx / A[i]) - (A.begin() + i + 1), 0LL);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:61:40: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   61 |                         else cnt += max(upper_bound(A.begin(), A.end(), idx / A[i]) - (A.begin() + i + 1), 0LL);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:12:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:61:40: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   61 |                         else cnt += max(upper_bound(A.begin(), A.end(), idx / A[i]) - (A.begin() + i + 1), 0LL);
      |                                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~