Buggy python submission (verdict: Time Limit Exceeded):
#大きな数の割り算は計算重いかも，for文内も掛け算の二分探索に

def main():
    import sys
    input = sys.stdin.readline

    N,K=map(int,input().split())
    A=list(map(int, input().split()))
    A.sort()

    #積がX未満になるものがK-1個以下になる最大のXを探す

    ng=10**18+1
    ok=-ng

    while ng-ok>1:
        X=(ok+ng)//2
        temp=0

        for i in range(N):
            if A[i]>0:
                #A[i]*A[j]がX未満となるjの個数を数える
                l=-1
                r=N
                while r-l>1:
                    med=(l+r)//2
                    if A[i]*A[med]<X:
                        l=med
                    else:
                        r=med
                temp+=r
                if r>i:
                    temp-=1

            elif A[i]<0:
                #A[i]*A[j]がX未満となるjの個数を数える
                l=-1
                r=N
                while r-l>1:
                    med=(l+r)//2
                    if A[i]*A[med]<X:
                        r=med
                    else:
                        l=med
                temp+=N-r
                if r<=i:
                    temp-=1

            else:
                if X>0:
                    temp+=N-1


        temp=temp//2

        if temp>=K:
            ng=X
        else:
            ok=X

    print(ok)


main()




Fixed submission:
#場合分け尺取り


n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if k<=ncc:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k=ncc-k
  while r-l!=1:
    mid=(l+r)//2
    cnt=0
    pos=c2-1
    for i in range(c1):
      while pos!=-1:
        if arr2[pos]>mid//arr1[i]:
          pos-=1
        else:
          break        
      cnt+=pos+1
    if cnt>k:
      r=mid
    else:
      l=mid
  print(-r)
elif k<=(ncc+zcc):
  print(0)
else:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k-=(ncc+zcc)
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    pos1=c1-1
    for i in range(c1):
      tmp=0
      while pos1!=-1:
        if arr1[pos1]>mid//arr1[i]:
          pos1-=1
        else:
          break
      tmp+=pos1+1
      if arr1[i]**2<mid:
        tmp-=1
      cnt1+=tmp
    cnt1=cnt1//2
    cnt2=0
    pos2=c2-1
    for i in range(c2):
      tmp=0
      while pos2!=-1:
        if arr2[pos2]>mid//arr2[i]:
          pos2-=1
        else:
          break
      tmp+=pos2+1
      if arr2[i]**2<mid:
        tmp-=1
      cnt2+=tmp
    cnt2=cnt2//2
    cnt=cnt1+cnt2
    if cnt>=k:
      r=mid
    else:
      l=mid
  print(r)

Buggy python submission (verdict: Time Limit Exceeded):
#大きな数の割り算は計算重いかも，for文内も掛け算の二分探索に


import bisect
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
A=list(map(int, input().split()))
A.sort()

#積がX未満になるものがK-1個以下になる最大のXを探す

ng=10**18+1
ok=-1*10**18+1

while abs(ng-ok)>1:
    X=(ok+ng)//2
    temp=0
    
    for i in range(N):
        if A[i]>0:
            #A[i]*A[j]がX未満となるjの個数を数える
            l=-1
            r=N
            while r-l>1:
                med=(l+r)//2
                if A[i]*A[med]<X:
                    l=med
                else:
                    r=med
            temp+=r

        elif A[i]<0:
            #A[i]*A[j]がX未満となるjの個数を数える
            l=-1
            r=N
            while r-l>1:
                med=(l+r)//2
                if A[i]*A[med]<X:
                    r=med
                else:
                    l=med
            temp+=N-r
            
        else:
            if X>0:
                temp+=N
        if A[i]*A[i]<X:
            temp-=1
            
    temp=temp//2
    if temp>=K:
        ng=X
    else:
        ok=X

print(ok)






Fixed submission:
#場合分け尺取り


n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if k<=ncc:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k=ncc-k
  while r-l!=1:
    mid=(l+r)//2
    cnt=0
    pos=c2-1
    for i in range(c1):
      while pos!=-1:
        if arr2[pos]>mid//arr1[i]:
          pos-=1
        else:
          break        
      cnt+=pos+1
    if cnt>k:
      r=mid
    else:
      l=mid
  print(-r)
elif k<=(ncc+zcc):
  print(0)
else:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k-=(ncc+zcc)
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    pos1=c1-1
    for i in range(c1):
      tmp=0
      while pos1!=-1:
        if arr1[pos1]>mid//arr1[i]:
          pos1-=1
        else:
          break
      tmp+=pos1+1
      if arr1[i]**2<mid:
        tmp-=1
      cnt1+=tmp
    cnt1=cnt1//2
    cnt2=0
    pos2=c2-1
    for i in range(c2):
      tmp=0
      while pos2!=-1:
        if arr2[pos2]>mid//arr2[i]:
          pos2-=1
        else:
          break
      tmp+=pos2+1
      if arr2[i]**2<mid:
        tmp-=1
      cnt2+=tmp
    cnt2=cnt2//2
    cnt=cnt1+cnt2
    if cnt>=k:
      r=mid
    else:
      l=mid
  print(r)

Buggy python submission (verdict: Time Limit Exceeded):
#大きな数の割り算は計算重いかも，for文内も二分探索に


import bisect
import sys
input = sys.stdin.readline

N,K=map(int,input().split())
A=list(map(int, input().split()))
A.sort()

#積がX未満になるものがK-1個以下になる最大のXを探す

ng=10**20
ok=-1*10**20

while abs(ng-ok)>1:
    X=(ok+ng)//2
    temp=0
    
    for i in range(N):
        if A[i]>0:
            #A[i]*A[j]がX未満となるjの個数を数える
            l=-1
            r=N
            while r-l>1:
                med=(l+r)//2
                if A[i]*A[med]<X:
                    l=med
                else:
                    r=med
            temp+=r

        elif A[i]<0:
            #A[i]*A[j]がX未満となるjの個数を数える
            l=-1
            r=N
            while r-l>1:
                med=(l+r)//2
                if A[i]*A[med]<X:
                    r=med
                else:
                    l=med
            temp+=N-r
            
        else:
            if X>0:
                temp+=N
        if A[i]*A[i]<X:
            temp-=1
            
    temp=temp//2
    #print(ok,X,ng,temp)
    #print("---")
    
    if temp>=K:
        ng=X
    else:
        ok=X

print(ok)






Fixed submission:
#場合分け尺取り


n,k=map(int,input().split())
arr=list(map(int,input().split()))
arr=sorted(arr)
nc=0
zc=0
pc=0
for i in range(n):
  if arr[i]<0:
    nc+=1
  elif arr[i]==0:
    zc+=1
  else:
    pc+=1
ncc=nc*pc
zcc=zc*(nc+pc)+(zc*(zc-1))//2
pcc=(nc*(nc-1))//2+(pc*(pc-1))//2
if k<=ncc:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k=ncc-k
  while r-l!=1:
    mid=(l+r)//2
    cnt=0
    pos=c2-1
    for i in range(c1):
      while pos!=-1:
        if arr2[pos]>mid//arr1[i]:
          pos-=1
        else:
          break        
      cnt+=pos+1
    if cnt>k:
      r=mid
    else:
      l=mid
  print(-r)
elif k<=(ncc+zcc):
  print(0)
else:
  arr1=[]
  arr2=[]
  for i in range(n):
    if arr[i]<0:
      arr1.append(-arr[i])
    elif arr[i]>0:
      arr2.append(arr[i])
  arr1=arr1[::-1]
  c1=len(arr1)
  c2=len(arr2)
  l=0
  r=10**18+1
  k-=(ncc+zcc)
  while r-l!=1:
    mid=(l+r)//2
    cnt1=0
    pos1=c1-1
    for i in range(c1):
      tmp=0
      while pos1!=-1:
        if arr1[pos1]>mid//arr1[i]:
          pos1-=1
        else:
          break
      tmp+=pos1+1
      if arr1[i]**2<mid:
        tmp-=1
      cnt1+=tmp
    cnt1=cnt1//2
    cnt2=0
    pos2=c2-1
    for i in range(c2):
      tmp=0
      while pos2!=-1:
        if arr2[pos2]>mid//arr2[i]:
          pos2-=1
        else:
          break
      tmp+=pos2+1
      if arr2[i]**2<mid:
        tmp-=1
      cnt2+=tmp
    cnt2=cnt2//2
    cnt=cnt1+cnt2
    if cnt>=k:
      r=mid
    else:
      l=mid
  print(r)