Language: C++

// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=100023};
ll a[N];
ll n;

il ll* lower(ll*l,ll*r,ll x,ll k){
	while( l<r ){
		ll*w = l+(r-l)/2;
		if( x*(*w)<=k ) r=w;
		else l=w+1;
	}
	return l;
}
il ll* upper(ll*l,ll*r,ll x,ll k){
	while( l<r ){
		ll*w = l+(r-l+1)/2;
		if( x*(*w)<=k ) l=w;
		else r=w-1;
	}
	return l;
}

il ll calc(ll w){
	ll ans = 0;
	rep(i,1,n){
		if( a[i]==0 ) ans+= w>=0 ? n-i:0 ;
		else if( a[i]>0 ){
			ans += max(0ll,upper(a+i,a+n,a[i],w)-a-i);
		}else{
			ans += max(0ll,n-(lower(a+i+1,a+n+1,a[i],w)-a)+1);
		}
//		printf("[%d] : %lld\n",i,ans);
	}
	return ans;
}

int main(){
	n=ci();
	ll k; scanf("%lld",&k);
	rep(i,1,n) a[i] = ci();
	sort(a+1,a+n+1);
	ll l=-1e18, r=1e18;
//	rep(i,-12,9) printf("%d : %lld\n",i,calc(i));
//	return 0;
	while( l<r ){
		ll w= l+(r-l)/2;
		if( calc(w)<k ) l=w+1;
		else r=w;
	}
	printf("%lld\n",l);
	return 0;
}


Compiler output:
a.cc: In function 'int ci()':
a.cc:16:23: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   16 |         register char ch;int f=1;
      |                       ^~
a.cc:18:22: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   18 |         register int x=ch^'0';
      |                      ^
a.cc: In function 'long long int calc(long long int)':
a.cc:46:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   46 |         rep(i,1,n){
      |             ^
a.cc:9:37: note: in definition of macro 'rep'
    9 | #define rep(i,s,t) for(register int i=(s);i<=(t);i++)
      |                                     ^
a.cc:49:35: error: no matching function for call to 'max(long long int, long int)'
   49 |                         ans += max(0ll,upper(a+i,a+n,a[i],w)-a-i);
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from a.cc:5:
/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:49:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'long int')
   49 |                         ans += max(0ll,upper(a+i,a+n,a[i],w)-a-i);
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/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:49:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   49 |                         ans += max(0ll,upper(a+i,a+n,a[i],w)-a-i);
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
a.cc: In function 'int main()':
a.cc:61:13: warning: ISO C++17 does not allow 'register' storage class specifier [-Wregister]
   61 |         rep(i,1,n) a[i] = ci();
      |             ^
a.cc:9:37: note: in definition of macro 'rep'
    9 | #define rep(i,s,t) for(register int i=(s);i<=(t);i++)
      |                                     ^