Language: C++

#include<bits/stdc++.h>
using namespace std;
long cmp(long x,long y,bool b){
  return (b?x<=y:x<y);
}
int main(){
  long n,k;cin>>n>>k;
  vector<long>P,N;
  for(long i=0;i<n;i++){
    long a;cin>>a;
    if(a>0)P.push_back(a);if(a<0)N.push_back(a);
  }
  if(k<=P.size()*N.size()){//マイナス
    //プラスとマイナスの掛け算
    sort(P.begin(),P.end(),greater<long>());sort(N.begin(),N.end());
    long l=-1000000000000000001,r=0;
    while(1){
      long z=(l+r)/2;
      long c[2]={0,0};
      for(int b=0;b<2;b++){
        long d=P.size();
        for(long i=0;i<N.size();i++){
          while(d>=0&&!cmp(N[i]*P[d-1],z,b))d--;
          c[b]+=max(d,0);
        }
      }
      if(k>c[1]){l=z;}
      else if(c[0]>=k){r=z;}
      else if(c[0]!=c[1]){
        cout<<z;return 0;
      }
    }  
  }
  else if(k>n*(n-1)/2-(P.size()*(P.size()-1)/2+N.size()*(N.size()-1)/2)){//プラス
    sort(P.begin(),P.end());sort(N.begin(),N.end(),greater<long>());
    k-=n*(n-1)/2-(P.size()*(P.size()-1)/2+N.size()*(N.size()-1)/2);//1から始まる
    long l=0,r=1000000000000000001;
    while(1){
      long z=(l+r)/2;
      long c[2]={0,0};
      for(int b=0;b<2;b++){
        long dp=P.size(),dn=N.size();
        for(long i=0;i<P.size();i++){
          while(dp>i&&!cmp(P[i]*P[dp-1],z,b))dp--;
          c[b]+=max((dp-i-1),0L);
          if(dp<=i)break;
        }
        for(long i=0;i<N.size();i++){
          while(dn>i&&!cmp(N[i]*N[dn-1],z,b))dn--;
          c[b]+=max((dn-i-1),0L);
          if(dn<=i)break;
        }    
      }
      if(k>c[1]){l=z;}
      else if(c[0]>=k){r=z;}
      else if(c[0]!=c[1]){
        cout<<z;return 0;
      }
    }  
  }
  else {  
    cout<<0;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:24:20: error: no matching function for call to 'max(long int&, int)'
   24 |           c[b]+=max(d,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:24:20: note:   deduced conflicting types for parameter 'const _Tp' ('long int' and 'int')
   24 |           c[b]+=max(d,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:24:20: note:   mismatched types 'std::initializer_list<_Tp>' and 'long int'
   24 |           c[b]+=max(d,0);
      |                 ~~~^~~~~