Language: C++

#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
vector<ll> vm, vm2, vp;
int m, p;
ll binarySearchMinus(ll k) {
  //二分探索を行う
  ll l = -ll(1e18) - 1, r = 0, mid, ans;
  while (r - l > 1) {
    mid = (l + r) / 2;
    ll cnt = 0;
    for (int i = 0; i < m && cnt < k; i++) {
      int j = 0;
      while (j < p && vm[i] * vp[p - j - 1] <= mid)
        j++;
      cnt += j;
    }
    if (cnt < k) {
      l = mid;
    } else {
      ans = mid;
      r = mid;
    }
  }
  return ans;
}
ll binarySearchPlus(ll k) {
  //二分探索を行う
  ll l = 0, r = ll(1e18) + 1, mid, ans;
  while (r - l > 1) {
    mid = (l + r) / 2;
    ll cnt = 0;
    for (int i = 0; i < m - 1 && cnt < k; i++) {
      cnt += max(0LL,
          (upper_bound(vm2.begin() + i, vm2.end(), mid / vm2[i]) - vm2.begin())
              - (i + 1));
    }
    for (int i = 0; i < p - 1 && cnt < k; i++) {
      cnt += max(0LL,
          (upper_bound(vp.begin() + i, vp.end(), mid / vp[i]) - vp.begin())
              - (i + 1));
    }
    if (cnt < k) {
      l = mid;
    } else {
      ans = mid;
      r = mid;
    }
  }
  return ans;
}
int main() {
  ll n, k, z = 0;
  cin >> n >> k;
  rep(i, n)
  {
    ll v;
    cin >> v;
    if (v < 0) {
      vm.push_back(v);
      vm2.push_back(-v);
    } else if (v == 0) {
      z++;
    } else {
      vp.push_back(v);
    }
  }
  sort(vp.begin(), vp.end());
  m = vm.size();
  p = vp.size();
  z = m * p + z * (z - 1) / 2 + z * (m + p);
  if (m * p >= k) {
    sort(vm.begin(), vm.end());
    //マイナス
    cout << binarySearchMinus(k);
  } else if (z >= k) {
    //ゼロ
    cout << 0;
  } else {
    sort(vm2.begin(), vm2.end());
    //プラス
    cout << binarySearchPlus(k - z);
  }
}

Compiler output:
a.cc: In function 'll binarySearchPlus(ll)':
a.cc:35:17: error: no matching function for call to 'max(long long int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   35 |       cnt += max(0LL,
      |              ~~~^~~~~
   36 |           (upper_bound(vm2.begin() + i, vm2.end(), mid / vm2[i]) - vm2.begin())
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |               - (i + 1));
      |               ~~~~~~~~~~
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:35:17: 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'})
   35 |       cnt += max(0LL,
      |              ~~~^~~~~
   36 |           (upper_bound(vm2.begin() + i, vm2.end(), mid / vm2[i]) - vm2.begin())
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |               - (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
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:35:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   35 |       cnt += max(0LL,
      |              ~~~^~~~~
   36 |           (upper_bound(vm2.begin() + i, vm2.end(), mid / vm2[i]) - vm2.begin())
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   37 |               - (i + 1));
      |               ~~~~~~~~~~
a.cc:40:17: error: no matching function for call to 'max(long long int, __gnu_cxx::__normal_iterator<long long int*, std::vector<long long int> >::difference_type)'
   40 |       cnt += max(0LL,
      |              ~~~^~~~~
   41 |           (upper_bound(vp.begin() + i, vp.end(), mid / vp[i]) - vp.begin())
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   42 |               - (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:40:17: 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'})
   40 |       cnt += max(0LL,
      |              ~~~^~~~~
   41 |           (upper_bound(vp.begin() + i, vp.end(), mid / vp[i]) - vp.begin())
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   42 |               - (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:40:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   40 |       cnt += max(0LL,
      |              ~~~^~~~~
   41 |           (upper_bound(vp.begin() + i, vp.end(), mid / vp[i]) - vp.begin())
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   42 |               - (i + 1));
      |               ~~~~~~~~~~