Language: C++

/**
 * author:    Ziel
 * created:   15.04.2020 14:38:24
**/

// ~zaletaet~

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#include <bits/stdc++.h>

#define fi first
#define se second
#define sz(x) int(x.size())
#define all(x) x.begin(), x.end()
#define pb push_back

using namespace std;

using ll = long long;
using ull = unsigned long long;
// using big = __int128_t; // -10^38...10^38
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

const ll N = 1e5 + 123, MOD = 1e9 + 7, oo = 1e9 + 9, INF = 2e18;
const double EPS = 1e-9, PI = acos(-1); // 3.14159265358979323846
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1}, dy[] = {0, 0, 1, -1, 1, -1, -1, 1};

main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	
	ll n, k;
	cin >> n >> k;
	
	vector<ll> pos, neg;
	ll zero = 0;
	for (int i = 0; i < n; i++) {
		ll x;
		cin >> x;
		
		if (x > 0) pos.pb(x);
		else if (x == 0) zero++;
		else neg.pb(-x);
	}
	
	sort(all(pos));
	sort(all(neg));
	
	auto check = [&](ll x) {
		ll res = 0;
		if (x >= 0) res += (sz(pos) * sz(neg)) + ((sz(pos) + sz(neg)) * zero) + (zero * (zero - 1) / 2);
		else {
			for (ll i: neg) {
				ll id;
				if ((-x) % i == 0) id = lower_bound(all(pos), (-x) / i) - pos.begin();
				else id = upper_bound(all(pos), (-x) / i) - pos.begin();
				res += sz(pos) - id;
			}
			return res;
		}
		
		if (x == 0) return res;
		
		for (int i = 0; i < sz(pos); i++) res += max(0ll, upper_bound(all(pos), x / pos[i]) - pos.begin() - i - 1);
		for (int i = 0; i < sz(neg); i++) res += max(0ll, upper_bound(all(neg), x / neg[i]) - neg.begin() - i - 1);
		
		return res;
	};
	
	ll low = -INF, high = INF;
	while (high - low > 1) {
		ll middle = (low + high) / 2;
		
		if (check(middle) < k) low = middle;
		else high = middle;
	}
	
	cout << high;
	return 0;
}



Compiler output:
a.cc:30:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main() {
      | ^~~~
a.cc: In lambda function:
a.cc:67:61: error: no matching function for call to 'max(long long int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   67 |                 for (int i = 0; i < sz(pos); i++) res += max(0ll, upper_bound(all(pos), x / pos[i]) - pos.begin() - i - 1);
      |                                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:10:
/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:67:61: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   67 |                 for (int i = 0; i < sz(pos); i++) res += max(0ll, upper_bound(all(pos), x / pos[i]) - pos.begin() - i - 1);
      |                                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:
/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:67:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   67 |                 for (int i = 0; i < sz(pos); i++) res += max(0ll, upper_bound(all(pos), x / pos[i]) - pos.begin() - i - 1);
      |                                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:68:61: error: no matching function for call to 'max(long long int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   68 |                 for (int i = 0; i < sz(neg); i++) res += max(0ll, upper_bound(all(neg), x / neg[i]) - neg.begin() - i - 1);
      |                                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:68:61: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and '__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type' {aka 'long int'})
   68 |                 for (int i = 0; i < sz(neg); i++) res += max(0ll, upper_bound(all(neg), x / neg[i]) - neg.begin() - i - 1);
      |                                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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
/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:68:61: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   68 |                 for (int i = 0; i < sz(neg); i++) res += max(0ll, upper_bound(all(neg), x / neg[i]) - neg.begin() - i - 1);
      |                                                          ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~