Problem: We have N integers A_1, A_2, ..., A_N.  There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Submission attempts (in order):
#abc_155_d
#versions of not using numpy
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = np.array(a)
a.sort()

left = -10**18
right = 10**18

while left+1 < right:
    mid = (left+right)//2
    cnt = 0
    
    #run about each element as the first choice
    for i in range(n):
        #count possible pairs that satisfies the condition      
        if(a[i] >= 0):
            #hold the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    l = m
                else:
                    r = m
            
            cnt += l+1
        
        if(a[i] < 0):
            #reverse the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    r = m
                else:
                    l = m
                    
            cnt += n - r
        
        if(a[i]**2 <= mid):
            cnt -= 1
        
    cnt /= 2
        
            
    
    
    
    if cnt >= k:
        right = mid
    if cnt < k:
        left=mid
   
        
print(right)

#abc_155_d
#versions of not using numpy
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = np.array(a)
a.sort()

left = -10**18
right = 10**18

while left+1 < right:
    mid = (left+right)//2
    cnt = 0
    
    #run about each element as the first choice
    for i in range(n):
        #count possible pairs that satisfies the condition      
        if(a[i] >= 0):
            #hold the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    l = m
                else:
                    r = m
            
            cnt += l+1
        
        if(a[i] < 0):
            #reverse the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    r = m
                else:
                    l = m
                    
            cnt += n - r
        
        if(a[i]**2 <= mid):
            cnt -= 1
        
    cnt /= 2
        
            
    
    
    
    if cnt >= k:
        right = mid
    if cnt < k:
        left=mid
   
        
print(right)

#abc_155_d
import numpy as np
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = np.array(a)
a.sort()

plus = a[a>0]
zero = a[a==0]
minus= a[a<0]

left = -10**18
right = 10**18

while left+1 < right:
    mid = (left+right)//2
    cnt = 0
    
    if mid >=0:
        cnt += len(zero) * n
    
    cnt += a.searchsorted(mid//plus, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid//minus), side="left")).sum()
    cnt -= np.count_nonzero(a*a <= mid)
    cnt /= 2
    
    if cnt >= k:
        right = mid
    if cnt < k:
        left=mid
        
print(right)

Verdicts: Runtime Error

Runtime Error

Accepted