Language: C++

#include <iostream>//cout<<right で右揃え
#include <iomanip>//cout<<setw(数字) で空白による桁揃え
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <cstdlib>//abs()で整数絶対値
#include <cmath>//abs()かfabs()で少数絶対値
#include <functional>//sort第三引数greater<型名>()で降順

using namespace std;
using ll = long long int;

vector<ll> plus,minus;

ll two_pointers(vector<ll> &minus,vector<ll> &plus,ll x){
    ll sum = 0;
    int right = plus.size() - 1;
    for(int i=0;i<minus.size();i++){
        for(int j=right;j>=0;j--){
            if(minus[i]*plus[j]<=x&&j!=0) continue;
            else if(minus[i]*plus[j]>x){
                sum += plus.size() - (j + 1);
                right = j;
                if(plus[0]==minus[0]&&i>j){
                    sum--;//sumにplus[i]^2が混じっているので取り除く
                }
                break;
            }else{
                sum += plus.size() * (minus.size() - i);
                if(plus[0]==minus[0]) sum -= minus.size() - i;
                right = -1;//これによりこのfor文は以降実行されない
            }
        }
    }
    return sum;
}

ll binary_search(bool which,ll xleft,ll xright ,vector<ll> &minus,vector<ll> &plus,ll K){
    while(xright-xleft>1){//leftを右に寄せて次のxを大きく　rightを左に寄せて次のxを小さく
        ll x = (xright + xleft) / 2;
        ll a = which ? (two_pointers(minus,minus,x) + two_pointers(plus,plus,x))/2
                     : two_pointers(minus,plus,x);
        if(K<=a) xright = x;//このxの値ではK番目の数<xの範囲の数の個数を数え上げている
        else xleft = x;//(a<K)このxの値では(x<K番目の数)の範囲の数の個数の数え上げで終わっている
    }
    return xright;
}

int main(){
    ll N,K;cin>>N>>K;
    ll zero = 0;
    for(int i=0;i<N;i++){
        int A;cin>>A;
        if(A>0) plus.push_back(A);
        else if(A<0) minus.push_back(A);
        else zero++;
    }

    sort(minus.begin(),minus.end(),greater<ll>());
    sort(plus.begin(),plus.end());

    ll pos = minus.size()*plus.size();
    if(K<=pos){//K番目の数は負である
        ll xleft = minus.back()*plus.back() - 1;
        ll xright = -1;
        cout << binary_search(false,xleft,xright,minus,plus,K) << endl;
    }else{
        pos += zero * ( minus.size() + plus.size() ) + zero * (zero-1) / 2;
        if(K<=pos) cout << 0 << endl;
        else{//K番目の数は正である
            ll xleft = 0;
            ll p = plus.size() - 1;
            ll m = minus.size() - 1;
            ll xright;
            if(p>=1&&m>=1) xright = max(plus[p]*plus[p-1],minus[m]*minus[m-1]);
            else if(p<1&&m>=1) xright = minus[m]*minus[m-1];//plusが1個以下
            else if(p>=1&&m<1) xright = plus[p]*plus[p-1];//minusが1個以下
            sort(plus.begin(),plus.end(),greater<ll>());
            sort(minus.begin(),minus.end());//減少配列にするための処理
            cout << binary_search(true,xleft,xright,minus,plus,K-pos) << endl;
        }
    }
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:55:17: error: reference to 'plus' is ambiguous
   55 |         if(A>0) plus.push_back(A);
      |                 ^~~~
In file included from /usr/include/c++/14/string:49,
                 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_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:56:22: error: reference to 'minus' is ambiguous
   56 |         else if(A<0) minus.push_back(A);
      |                      ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:60:10: error: reference to 'minus' is ambiguous
   60 |     sort(minus.begin(),minus.end(),greater<ll>());
      |          ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:60:24: error: reference to 'minus' is ambiguous
   60 |     sort(minus.begin(),minus.end(),greater<ll>());
      |                        ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:61:10: error: reference to 'plus' is ambiguous
   61 |     sort(plus.begin(),plus.end());
      |          ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:61:23: error: reference to 'plus' is ambiguous
   61 |     sort(plus.begin(),plus.end());
      |                       ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:63:14: error: reference to 'minus' is ambiguous
   63 |     ll pos = minus.size()*plus.size();
      |              ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:63:27: error: reference to 'plus' is ambiguous
   63 |     ll pos = minus.size()*plus.size();
      |                           ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:65:20: error: reference to 'minus' is ambiguous
   65 |         ll xleft = minus.back()*plus.back() - 1;
      |                    ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:65:33: error: reference to 'plus' is ambiguous
   65 |         ll xleft = minus.back()*plus.back() - 1;
      |                                 ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:67:50: error: reference to 'minus' is ambiguous
   67 |         cout << binary_search(false,xleft,xright,minus,plus,K) << endl;
      |                                                  ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:67:56: error: reference to 'plus' is ambiguous
   67 |         cout << binary_search(false,xleft,xright,minus,plus,K) << endl;
      |                                                        ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:69:25: error: reference to 'minus' is ambiguous
   69 |         pos += zero * ( minus.size() + plus.size() ) + zero * (zero-1) / 2;
      |                         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:69:40: error: reference to 'plus' is ambiguous
   69 |         pos += zero * ( minus.size() + plus.size() ) + zero * (zero-1) / 2;
      |                                        ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:73:20: error: reference to 'plus' is ambiguous
   73 |             ll p = plus.size() - 1;
      |                    ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:74:20: error: reference to 'minus' is ambiguous
   74 |             ll m = minus.size() - 1;
      |                    ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:76:41: error: reference to 'plus' is ambiguous
   76 |             if(p>=1&&m>=1) xright = max(plus[p]*plus[p-1],minus[m]*minus[m-1]);
      |                                         ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:76:49: error: reference to 'plus' is ambiguous
   76 |             if(p>=1&&m>=1) xright = max(plus[p]*plus[p-1],minus[m]*minus[m-1]);
      |                                                 ^~~~
/usr/include/c++/14/bits/stl_function.h:160:12: note: candidates are: 'template<class _Tp> struct std::plus'
  160 |     struct plus;
      |            ^~~~
a.cc:14:12: note:                 'std::vector<long long int> plus'
   14 | vector<ll> plus,minus;
      |            ^~~~
a.cc:76:59: error: reference to 'minus' is ambiguous
   76 |             if(p>=1&&m>=1) xright = max(plus[p]*plus[p-1],minus[m]*minus[m-1]);
      |                                                           ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:76:68: error: reference to 'minus' is ambiguous
   76 |             if(p>=1&&m>=1) xright = max(plus[p]*plus[p-1],minus[m]*minus[m-1]);
      |                                                                    ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:77:41: error: reference to 'minus' is ambiguous
   77 |             else if(p<1&&m>=1) xright = minus[m]*minus[m-1];//plusが1個以下
      |                                         ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> minus'
   14 | vector<ll> plus,minus;
      |                 ^~~~~
a.cc:77:50: error: reference to 'minus' is ambiguous
   77 |             else if(p<1&&m>=1) xright = minus[m]*minus[m-1];//plusが1個以下
      |                                                  ^~~~~
/usr/include/c++/14/bits/stl_function.h:163:12: note: candidates are: 'template<class _Tp> struct std::minus'
  163 |     struct minus;
      |            ^~~~~
a.cc:14:17: note:                 'std::vector<long long int> min