Language: C++

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <stack>
#include <unordered_map>
#include <vector>
typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 1e18;
const double INFD = 1e30;
const double EPS = 1e-6;
const double PI = acos(-1);
const int MOD = 1e9 + 7;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 200005;
int n, m;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;

ll asc[MAXN], des[MAXN];
ll k;
vector<ll> neg, pos, zeros;
bool check(ll x) {
    ll cnt = 0;
    if (x >= 0) {
        int sz = pos.size();
        for (int i = 0; i < sz; i++) {
            if (pos[i] == 0) continue;
            auto p = upper_bound(pos.begin(), pos.end(), x / pos[i]);
            int c = min((ll)i, p - pos.begin());
            cnt += c;
        }

        sz = neg.size();
        for (int i = 0; i < sz; i++) {
            if (neg[i] == 0) break;
            auto p = lower_bound(neg.begin(), neg.end(), x / neg[i]);
            int kk = max((ll)i + 1, (p - neg.begin()));
            int c = sz - kk;
            cnt += c;
        }
        cnt += (zeros.size()) * (zeros.size() - 1LL) / 2LL;
        x = -1;
    }
    for (int i = 1; i <= n; i++) {
        if (asc[i] >= 0) break;
        auto p = lower_bound(asc + 1, asc + n + 1, (x + asc[i] + 1) / asc[i]);
        cnt += n - (p - asc) + 1;
    }

    return cnt >= k;
}
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    n = read<int>(), k = read<int>();
    for (int i = 1; i <= n; i++) {
        asc[i] = read<ll>();
        if (asc[i] <= 0) neg.push_back(asc[i]);
        if (asc[i] >= 0) pos.push_back(asc[i]);
        if (asc[i] == 0) zeros.push_back(asc[i]);
    }
    sort(asc + 1, asc + n + 1);
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    check(9);
    ll l = (ll)-1e18, r = (ll)1e18;
    ll ans = r;
    while (l <= r) {
        ll mid = (l + r) / 2;
        if (check(mid)) {
            ans = mid, r = mid - 1;
        } else {
            l = mid + 1;
        }
    }
    printf("%lld", ans);
    return 0;
}

Compiler output:
a.cc: In function 'bool check(ll)':
a.cc:51:24: error: no matching function for call to 'min(ll, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   51 |             int c = min((ll)i, p - pos.begin());
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:51:24: 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'})
   51 |             int c = min((ll)i, p - pos.begin());
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281: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:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:51:24: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |             int c = min((ll)i, p - pos.begin());
      |                     ~~~^~~~~~~~~~~~~~~~~~~~~~~~
a.cc:59:25: error: no matching function for call to 'max(ll, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   59 |             int kk = max((ll)i + 1, (p - neg.begin()));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:59:25: 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'})
   59 |             int kk = max((ll)i + 1, (p - neg.begin()));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:59:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   59 |             int kk = max((ll)i + 1, (p - neg.begin()));
      |                      ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~