Language: C++

#include <cstdio>
#include <cmath>
#include <algorithm>
#define N 200005

int n;
long long a[N];

inline long long cnt(long long x) {
    long long ans = 0;
    for (int i = 0; i < n; ++i)
        if (!a[i]) ans += x >= 0 ? n - i - 1 : 0;
        else if (a[i] < 0) ans += std::min(n - i - 1, a + n - std::lower_bound(a, a + n, (long long)std::ceil((long double)x / a[i])));
        else if (a[i] > 0) ans += std::max(0, std::upper_bound(a, a + n, (long long)std::floor((long double)x / a[i])) - a - i - 1);
    return ans;
}

int main() {
    long long k;
    scanf("%d%lld", &n, &k);
    for (int i = 0; i < n; ++i) scanf("%lld", a + i);
    std::sort(a, a + n);
    for (int i = 0; i < n; ++i) printf("%lld ", a[i]); puts("");
    long long l = -1e18, r = 1e18;
    while (l < r) {
        long long mid = l + r >> 1;
        if (cnt(mid) < k) l = mid + 1;
        else r = mid;
    }
    printf("%lld\n", l);
    return 0;
}


Compiler output:
a.cc: In function 'long long int cnt(long long int)':
a.cc:13:43: error: no matching function for call to 'min(int, long int)'
   13 |         else if (a[i] < 0) ans += std::min(n - i - 1, a + n - std::lower_bound(a, a + n, (long long)std::ceil((long double)x / a[i])));
      |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:2:
/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:13:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
   13 |         else if (a[i] < 0) ans += std::min(n - i - 1, a + n - std::lower_bound(a, a + n, (long long)std::ceil((long double)x / a[i])));
      |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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,
                 from a.cc:3:
/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:13:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   13 |         else if (a[i] < 0) ans += std::min(n - i - 1, a + n - std::lower_bound(a, a + n, (long long)std::ceil((long double)x / a[i])));
      |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc:14:43: error: no matching function for call to 'max(int, long int)'
   14 |         else if (a[i] > 0) ans += std::max(0, std::upper_bound(a, a + n, (long long)std::floor((long double)x / a[i])) - a - 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:14:43: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long int')
   14 |         else if (a[i] > 0) ans += std::max(0, std::upper_bound(a, a + n, (long long)std::floor((long double)x / a[i])) - a - 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:14:43: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   14 |         else if (a[i] > 0) ans += std::max(0, std::upper_bound(a, a + n, (long long)std::floor((long double)x / a[i])) - a - i - 1);
      |                                   ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~