Buggy python submission (verdict: Time Limit Exceeded):
#積がmid以下になるようなペアの数を求めるのが難しいところだが、うまく解決している
N, K = map(int, input().split())
zero, plus, minus = 0, [], []
for x in map(int, input().split()):
    if x == 0:
        zero += 1
    elif x > 0:
        plus.append(x)
    else:
        minus.append(x)

#絶対値が小さい順にソートしておく
plus.sort()
minus.sort(reverse=True)

#二分探索する
#cntは積がmid以下になるようなペアの数
ok, ng = 10**19, -10**19
while ok - ng > 1:
    mid = (ok + ng) // 2
    cnt = 0
    #この条件分岐で積が0になるペアの数を反映
    if mid >= 0:
        cnt += zero * (zero-1) // 2 + zero * (N-zero)

    if mid > 0:
        cnt += len(minus) * len(plus)
        #両方プラスと両方マイナスをまとめて扱っている
        for a in (plus, minus):
            l, r = 0, len(a)-1
            while l < r:
                while l < r and a[l]*a[r] > mid:
                    r -= 1
                cnt += r - l
                l += 1

    else:
        r = len(minus)-1
        for l in range(len(plus)):
            while r >= 0 and plus[l] * minus[r] <= mid:
                r -= 1
            cnt += len(minus) - r - 1

    if cnt >= K:
        ok = mid
    else:
        ng = mid

print(ok)


Fixed submission:
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil,pi,factorial
    from operator import itemgetter
    def I(): return int(input())
    def MI(): return map(int, input().split())
    def LI(): return list(map(int, input().split()))
    def LI2(): return [int(input()) for i in range(n)]
    def MXI(): return [[LI()]for i in range(n)]
    def SI(): return input().rstrip()
    def printns(x): print('\n'.join(x))
    def printni(x): print('\n'.join(list(map(str,x))))
    inf = 10**17
    mod = 10**9 + 7
#main code here!
    n,k=MI()
    lis=LI()
    p,z,m=0,0,0
    plus=[]
    minus=[]
    for i in range(n):
        if lis[i]>0:
            p+=1
            plus.append(lis[i])
        elif lis[i]==0:
            z+=1
        else:
            m+=1
            minus.append(lis[i])
    plus.sort()
    minus.sort()
    #print(plus)
    #print(minus)
    #plus,minus,sort
    resm=p*m
    resz=z*p+z*m+p*m+z*(z-1)//2
    if k<=resm:
        left=-10**18-1
        right=-1
        while left+1<right:
            x=(left+right)//2
            i=0
            ans=0
            j=0
            while i<p:
                while j<m:
                    if plus[i]*minus[j]<=x:
                        if j==m-1:
                            ans+=m
                            i+=1
                            break
                        j+=1
                    else:
                        i+=1
                        ans+=j
                        break
            #print(left,right,x,ans)
            if ans>=k:
                right=x
            else:
                left=x
        print(right)
    
    elif k<=resz:
        print(0)
        sys.exit()
    else:
        k=k-resz
        #print(k)
        left=0
        right=10**18
        square=[]
        for i in range(p):
            square.append(plus[i]**2)
        for i in range(m):
            minus[i]*=(-1)
            square.append(minus[i]**2)
        square.sort()
        plus.sort()
        minus.sort()
        plus2=sorted(plus,reverse=True)  
        minus2=sorted(minus,reverse=True)
        while left+1<right:
            x=(left+right)//2
            i=0
            ans=0
            j=0
            zure=bisect_right(square,x)-1
            while i<p:
                while j<p:
                    if plus2[i]*plus[j]<=x:
                        if j==p-1:
                            ans+=p
                            i+=1
                            break
                        j+=1
                    else:
                        i+=1
                        ans+=j
                        break
            i=0
            j=0
            while i<m:
                while j<m:
                    if minus2[i]*minus[j]<=x:
                        if j==m-1:
                            ans+=m
                            i+=1
                            break
                        j+=1
                    else:
                        i+=1
                        ans+=j
                        break
            #print(left,right,x,ans,zure,(ans-zure)//2)
            if (ans-zure)//2>=k:
                right=x
            else:
                left=x
        print(right)
            
if __name__=="__main__":
    main()