Language: C++

#include <bits/stdc++.h>
using namespace std;
long long N, K;
vector<long long> v;
vector<long long> a, b, c;
long long A, B, C;
int count(long long x) {
    // x以下の個数
    if (x == 0) {
        return (N*(N-1)/2) - (A*(A-1)/2) - (C*(C-1)/2);
    }
    if (x < 0) {
        long long res = 0;
        for (int i = 0; i < A; i++) {
            if ((-x) % a[i] == 0) {
                res += c.end() - (lower_bound(c.begin(), c.end(), (-x)/a[i]));
            }
            else {
                res += c.end() - (lower_bound(c.begin(), c.end(), (-x)/a[i]+1));
            }
        }
        return res;
    }
    if (x > 0) {
        long long res = (N*(N-1)/2) - (A*(A-1)/2) - (C*(C-1)/2);
        for (int i = 0; i < A; i++) {
            res += max(upper_bound(a.begin(), a.end(), x/a[i]) - a.begin() - (i+1), 0);
        }
        for (int i = 0; i < C; i++) {
            res += max(upper_bound(c.begin(), c.end(), x/c[i]) - c.begin() - (i+1), 0);
        }
        return res;
    }
}
int main () {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        int x;
        cin >> x;
        v.push_back(x);
        if (x > 0) {
            a.push_back(x);
        }
        else if (x == 0) {
            b.push_back(x);
        }
        else {
            c.push_back(-x);
        }
    }
    A = a.size(), B = b.size(), C = c.size();
    sort(v.begin(), v.end());
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    long long low = -pow(10, 18)-1, high = pow(10, 18)+1;
    while (high - low > 1) {
        long long mid = (high + low) / 2;
        long long k = count(mid);
        if (k < K) {
            low = mid;
        }
        else {
            high = mid;
        }
    }
    cout << high << endl;
}

Compiler output:
a.cc: In function 'int count(long long int)':
a.cc:27:23: error: no matching function for call to 'max(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type, int)'
   27 |             res += max(upper_bound(a.begin(), a.end(), x/a[i]) - a.begin() - (i+1), 0);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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:27:23: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   27 |             res += max(upper_bound(a.begin(), a.end(), x/a[i]) - a.begin() - (i+1), 0);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:27:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   27 |             res += max(upper_bound(a.begin(), a.end(), x/a[i]) - a.begin() - (i+1), 0);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:30:23: error: no matching function for call to 'max(__gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type, int)'
   30 |             res += max(upper_bound(c.begin(), c.end(), x/c[i]) - c.begin() - (i+1), 0);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:30:23: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   30 |             res += max(upper_bound(c.begin(), c.end(), x/c[i]) - c.begin() - (i+1), 0);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:30:23: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   30 |             res += max(upper_bound(c.begin(), c.end(), x/c[i]) - c.begin() - (i+1), 0);
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:34:1: warning: control reaches end of non-void function [-Wreturn-type]
   34 | }
      | ^