Language: C++

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
template<class A, class B> ostream& operator <<(ostream& out, const pair<A, B> &p) {
    return out << "(" << p.first << ", " << p.second << ")";
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const multiset<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template<class T> inline void YES(T condition) { 
    if(condition) cout << "YES" << endl;
    else cout << "NO" << endl;
}
template<class T> inline void Yes(T condition) {
    if(condition) cout << "Yes" << endl;
    else cout << "No" << endl;
}
template<class T> T gcd(T a, T b) {
    if(a && b) { return gcd(min(a, b), max(a, b) % min(a, b)); }
    else { return a; }
}
template<class T> T lcm(T a, T b){
    return a / gcd(a, b) * b;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);


    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<int> neg;
    vector<int> pos;
    LL zcnt = 0;
    for (auto& v: a) {
        if (v < 0) neg.push_back(v);
        else if (v == 0) zcnt++;
        else pos.push_back(v);
    }
    sort(neg.begin(), neg.end());
    sort(pos.begin(), pos.end());
    int nsize = (int)neg.size();
    int psize = (int)pos.size();
    LL negcnt = 1LL * nsize * psize;
    LL zeros = 1LL * zcnt * (n - zcnt) + 1LL * zcnt * (zcnt - 1) / 2;
    
    // cout << neg << endl;
    // cout << pos << endl;
    // cout << "negcnt:" << negcnt << endl;
    // cout << "zeros:" << zeros << endl;

    auto negRank = [&](LL x) {
        LL res = 0;
        for (auto& ne: neg) {
            LL y = x / ne;
            if (y > 1e9) continue;
            int z = (int)y;
            res += pos.end() - upper_bound(pos.begin(), pos.end(), z);
        }
        return res;
    };

    auto posRank = [&](LL x) {
        LL res = 0;
        for (auto it = neg.begin(); it != neg.end(); it++) {
            int ne = *it;
            LL y = (x - ne + 1) / ne;
            int bound = neg.end() - it - 1;
            if (y < -1e9) {res += bound; continue;}
            int z = (int)y;
            int cnts = neg.end() - upper_bound(neg.begin(), neg.end(), z);
            res += max(0, min(bound, cnts));
        }
        // cout << x << "--" << res << endl;
        for (auto it = pos.begin(); it != pos.end(); it++) {
            int po = *it;
            LL y = (x + po - 1) / po;
            if (y > 1e9) {res += it - pos.begin(); continue;}
            int z = (int)y;
            res += max(0, lower_bound(pos.begin(), it, z) - pos.begin());
            // cout << "      " << x << " " << y <<":" << res << endl;
        }
        // cout << x << "++" << res << endl;
        return res;
    };

    auto Rank = [&] (LL x) {
        LL rk;
        if (x < 0) rk = negRank(x);
        else if (x == 0) rk = negcnt;
        else rk = negcnt + zeros + posRank(x);
        // cout << x << ":" << rk << endl;
        return rk;
    };

    LL l = -1e18, r = 1e18;
    while (l < r) {
        LL mid =  (l + r) >> 1;
        LL rk = Rank(mid);
        if (rk < k) l = mid + 1;
        else r = mid;
    }
    cout << l - 1 << '\n';

    return 0;
}


Compiler output:
a.cc: In lambda function:
a.cc:111:23: error: no matching function for call to 'max(int, __gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type)'
  111 |             res += max(0, lower_bound(pos.begin(), it, z) - pos.begin());
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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: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:111:23: note:   deduced conflicting types for parameter 'const _Tp' ('int' and '__gnu_cxx::__normal_iterator<int*, std::vector<int> >::difference_type' {aka 'long int'})
  111 |             res += max(0, lower_bound(pos.begin(), it, z) - pos.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
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:111:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
  111 |             res += max(0, lower_bound(pos.begin(), it, z) - pos.begin());
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~