Language: C++

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef std::vector<int64_t> vI;

template<typename T>
ostream& operator<<(ostream& os, vector<T> const& v) {
  os << "[";
  for (size_t i = 0; i < v.size(); i++) {
    os << (i == 0 ? "" : ",") << v[i];
  }
  return os << "]";
}

int64_t count_lower(int64_t v, vI aa) {
//  std::cerr << "aa=" << aa << std::endl;
//  std::cerr << "count_lower v=" << v << std::endl;
  int64_t r = 0;
  for (size_t i = 0; i < aa.size() - 1; i++) {
    if (aa[i] < 0ll) {
      size_t lb = i, ub = aa.size() - 1;
//      std::cerr << "aa[i]=" << aa[i] << ",aa[ub]=" << aa[ub] << ",v=" << v << std::endl;
      if (aa[i] * aa[ub] >= v) continue;
      while (ub - lb > 1) {
        size_t mid = (lb + ub) / 2;
//        if (mid < 0) {mid = (lb + ub - 1) / 2; }
        if (aa[i] * aa[mid] >= v) {
          lb = mid;
        } else {
          ub = mid;
        }
      }
      r += aa.size() - ub;
    } else if (aa[i] == 0) {
      if (v > 0) r += aa.size() - i - 1;
    } else {
      size_t lb = i + 1;
      size_t ub = aa.size();
//      std::cerr << "aa[i]=" << aa[i] << ",aa[lb]=" << aa[lb] << ",v=" << v << std::endl;
      if (aa[i] * aa[lb] >= v) continue;
      while (ub - lb > 1) {
        size_t mid = (lb + ub) / 2;
//        if (mid < 0) {mid = (lb + ub - 1) / 2; }
        if (aa[i] * aa[mid] >= v) {
          ub = mid;
        } else {
          lb = mid;
        }
      }
      r += lb - i;
    }
//    std::cerr << "i=" << i << ",r=" << r << std::endl;
  }
//  std::cerr << "r=" << r << std::endl;
  return r;
}

int main() {
  int64_t n, k;
  std::cin >> n >> k;
//  std::cerr << "n=" << n << ",k=" << k << std::endl;
  vI aa(n);
  for (int64_t i = 0; i < n; i++) std::cin >> aa[i];
  std::sort(aa.begin(), aa.end());
  int64_t lb = std::min(aa[0] * aa[1], std::min(aa[0] * aa[aa.size() -1], 0ll));
  int64_t ub = std::max(aa[0] * aa[1], aa[aa.size() - 2] * aa[aa.size() - 1]) + 1;  
//  std::cerr << "lb=" << lb << ",ub=" << ub << std::endl;
  while (ub - lb > 1) {
    int64_t mid = (lb + ub) / 2;
//    if (mid < 0) {mid = (lb + ub - 1) / 2; }
//    std::cerr << "lb=" << lb << ",ub=" << ub << ",mid=" << mid << std::endl;
//    std::cerr << "countlower(mid=" << mid << ")=" << count_lower(mid, aa) << std::endl;
    if (count_lower(mid, aa) <= k - 1) {
      lb = mid;
    } else {
      ub = mid;
    }
  }
  std::cout << lb << std::endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:66:48: error: no matching function for call to 'min(__gnu_cxx::__alloc_traits<std::allocator<long int>, long int>::value_type, long long int)'
   66 |   int64_t lb = std::min(aa[0] * aa[1], std::min(aa[0] * aa[aa.size() -1], 0ll));
      |                                        ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 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:66:48: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'long long int')
   66 |   int64_t lb = std::min(aa[0] * aa[1], std::min(aa[0] * aa[aa.size() -1], 0ll));
      |                                        ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:66:48: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   66 |   int64_t lb = std::min(aa[0] * aa[1], std::min(aa[0] * aa[aa.size() -1], 0ll));
      |                                        ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~