Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a_plus = [x for x in a if x >= 0]
a_minus = [x for x in a if x < 0]

def count_no_more_than(l):
    cnt = 0
    for x in a_plus:
        y_p = n
        while y_p-1 >= 0 and a[y_p-1] * x > l:
            y_p -= 1
        cnt += y_p

    for x in a_minus:
        y_p = -1
        while y_p+1 < n and a[y_p+1] * x > l:
            y_p += 1
        cnt += n-1 - y_p

    for x in a:
        if x * x <= l:
            cnt -= 1
        
    cnt //= 2
    return cnt

bottom = -(10**18)-1 # <k
top = 10**18 + 1     # >=k

while top - bottom > 1:
    mid = (top + bottom) // 2
    if count_no_more_than(mid) < k:
        bottom = mid
    else:
        top = mid

print(top)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
minus = [-x for x in a if x < 0]
plus = [x for x in a if x >= 0]

minus.sort()
plus.sort()

def cnt(x):
    ans = 0
    if x < 0:
        x = -x
        r = 0
        for num in minus[::-1]:
            while r < len(plus) and plus[r] * num < x:
                r += 1
            ans += len(plus) -  r
        return ans

    r = 0
    for num in minus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(minus) and minus[r] * num <= x:
            r += 1
        ans += r
    r = 0
    for num in plus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(plus) and plus[r] * num <= x:
            r += 1
        ans += r
    ans //= 2
    ans += len(minus) * len(plus)    
    return ans

bottom = 0
top = 2*(10**18) + 2


while top - bottom > 1:
    mid = (top + bottom) // 2
    if cnt(mid - 10**18-1) < k:
        bottom = mid
    else:
        top = mid

print(int(top - 10**18-1))

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
a_plus = [x for x in a if x >= 0]
a_minus = [x for x in a if x < 0]

def count_no_more_than(l):
    cnt = 0
    for x in a_plus:
        y_p = n
        while y_p-1 >= 0 and a[y_p-1] * x > l:
            y_p -= 1
        cnt += y_p

    for x in a_minus:
        y_p = -1
        while y_p+1 < n and a[y_p+1] * x > l:
            y_p += 1
        cnt += n-1 - y_p

    for x in a:
        if x * x <= l:
            cnt -= 1
        
    cnt //= 2
    return cnt

bottom = -(10**18)-1 # <k
top = 10**18 + 1     # >=k

while top - bottom > 1:
    mid = (top + bottom) // 2
    if count_no_more_than(mid) < k:
        bottom = mid
    else:
        top = mid

print(top)

Fixed submission:
n, k = map(int, input().split())
a = list(map(int, input().split()))
minus = [-x for x in a if x < 0]
plus = [x for x in a if x >= 0]

minus.sort()
plus.sort()

def cnt(x):
    ans = 0
    if x < 0:
        x = -x
        r = 0
        for num in minus[::-1]:
            while r < len(plus) and plus[r] * num < x:
                r += 1
            ans += len(plus) -  r
        return ans

    r = 0
    for num in minus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(minus) and minus[r] * num <= x:
            r += 1
        ans += r
    r = 0
    for num in plus[::-1]:
        if num * num <= x: ans -= 1
        while r < len(plus) and plus[r] * num <= x:
            r += 1
        ans += r
    ans //= 2
    ans += len(minus) * len(plus)    
    return ans

bottom = 0
top = 2*(10**18) + 2


while top - bottom > 1:
    mid = (top + bottom) // 2
    if cnt(mid - 10**18-1) < k:
        bottom = mid
    else:
        top = mid

print(int(top - 10**18-1))