Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
  N,K = map(int,input().split())
  A = sorted(list(map(int,input().split())))

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    for a in A:
      if a >= 0:
        ll = -1
        rr = N
        while(ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            ll = cc
          else:
            rr = cc
        x += ll+1
      else:
        ll = -1
        rr = N
        while (ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            rr = cc
          else:
            ll = cc
        x += N-rr
      if a*a < c:
        x -=1
    x //= 2
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
  N,K = map(int,input().split())
  A = sorted(list(map(int,input().split())))
  
  AM = []
  AP = []
  for a in A:
    if a > 0:
      AP.append(a)
    elif a < 0:
      AM.append(a)

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    if c > 0:
      i = len(AP)-1
      for j in range(len(AP)):
        if j >= i:
          break
        while(j < i and AP[i]*AP[j] >= c):
          i -= 1
        x += i-j
      i = 0
      for j in range(len(AM)-1,-1,-1):
        if j <= i:
          break
        while (i < j and AM[i]*AM[j] >= c):
          i += 1
        x += j-i
      #print(c,x)
      x += len(AP)*len(AM)
      x += (len(AP)+len(AM))*(N-len(AP)-len(AM))
      if N-len(AP)-len(AM) > 1:
        x += (N-len(AP)-len(AM))*(N-len(AP)-len(AM)-1)//2
    elif c == 0:
      x += len(AP)*len(AM)
    else:
      i = 0
      for j in range(len(AM)):
        while(i < len(AP) and AP[i]*AM[j] >= c):
          i += 1
        x += len(AP)-i

    #print(l,r,c,x)
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N,K = map(int,input().split())
  A = sorted(list(map(int,input().split())))

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    for a in A:
      if a >= 0:
        ll = -1
        rr = N
        while(ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            ll = cc
          else:
            rr = cc
        x += ll+1
      else:
        ll = -1
        rr = N
        while (ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            rr = cc
          else:
            ll = cc
        x += N-rr
      if a*a < c:
        x -=1
    x //= 2
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
  N,K = map(int,input().split())
  A = sorted(list(map(int,input().split())))
  
  AM = []
  AP = []
  for a in A:
    if a > 0:
      AP.append(a)
    elif a < 0:
      AM.append(a)

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    if c > 0:
      i = len(AP)-1
      for j in range(len(AP)):
        if j >= i:
          break
        while(j < i and AP[i]*AP[j] >= c):
          i -= 1
        x += i-j
      i = 0
      for j in range(len(AM)-1,-1,-1):
        if j <= i:
          break
        while (i < j and AM[i]*AM[j] >= c):
          i += 1
        x += j-i
      #print(c,x)
      x += len(AP)*len(AM)
      x += (len(AP)+len(AM))*(N-len(AP)-len(AM))
      if N-len(AP)-len(AM) > 1:
        x += (N-len(AP)-len(AM))*(N-len(AP)-len(AM)-1)//2
    elif c == 0:
      x += len(AP)*len(AM)
    else:
      i = 0
      for j in range(len(AM)):
        while(i < len(AP) and AP[i]*AM[j] >= c):
          i += 1
        x += len(AP)-i

    #print(l,r,c,x)
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N,K = map(int,input().split())
  A = sorted(list(map(int,input().split())))

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    for a in A:
      if a >= 0:
        ll = -1
        rr = N
        while(ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            ll = cc
          else:
            rr = cc
        x += ll+1
      else:
        ll = -1
        rr = N
        while (ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            rr = cc
          else:
            ll = cc
        x += N-rr
      if a*a < c:
        x -=1
    x //= 2
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()


Fixed submission:
import sys
input = sys.stdin.readline

def main():
  N,K = map(int,input().split())
  A = sorted(list(map(int,input().split())))
  
  AM = []
  AP = []
  for a in A:
    if a > 0:
      AP.append(a)
    elif a < 0:
      AM.append(a)

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    if c > 0:
      i = len(AP)-1
      for j in range(len(AP)):
        if j >= i:
          break
        while(j < i and AP[i]*AP[j] >= c):
          i -= 1
        x += i-j
      i = 0
      for j in range(len(AM)-1,-1,-1):
        if j <= i:
          break
        while (i < j and AM[i]*AM[j] >= c):
          i += 1
        x += j-i
      #print(c,x)
      x += len(AP)*len(AM)
      x += (len(AP)+len(AM))*(N-len(AP)-len(AM))
      if N-len(AP)-len(AM) > 1:
        x += (N-len(AP)-len(AM))*(N-len(AP)-len(AM)-1)//2
    elif c == 0:
      x += len(AP)*len(AM)
    else:
      i = 0
      for j in range(len(AM)):
        while(i < len(AP) and AP[i]*AM[j] >= c):
          i += 1
        x += len(AP)-i

    #print(l,r,c,x)
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()

Buggy python submission (verdict: Time Limit Exceeded):
N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))

INF = 10**18+1
l = -INF
r = INF
while(l+1 < r):
  # 積がc未満となるペアの個数xを求める。
  # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
  c = (l+r)//2
  x = 0
  for a in A:
    if a >= 0:
      ll = -1
      rr = N
      while(ll+1 < rr):
        cc = (ll+rr)//2
        if a*A[cc] < c:
          ll = cc
        else:
          rr = cc
      x += ll+1
    else:
      ll = -1
      rr = N
      while (ll+1 < rr):
        cc = (ll+rr)//2
        if a*A[cc] < c:
          rr = cc
        else:
          ll = cc
      x += N-rr
    if a*a < c:
      x -=1
  x //= 2
  if x < K:
    l = c
  else:
    r = c
print(l)


Fixed submission:
import sys
input = sys.stdin.readline

def main():
  N,K = map(int,input().split())
  A = sorted(list(map(int,input().split())))
  
  AM = []
  AP = []
  for a in A:
    if a > 0:
      AP.append(a)
    elif a < 0:
      AM.append(a)

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    if c > 0:
      i = len(AP)-1
      for j in range(len(AP)):
        if j >= i:
          break
        while(j < i and AP[i]*AP[j] >= c):
          i -= 1
        x += i-j
      i = 0
      for j in range(len(AM)-1,-1,-1):
        if j <= i:
          break
        while (i < j and AM[i]*AM[j] >= c):
          i += 1
        x += j-i
      #print(c,x)
      x += len(AP)*len(AM)
      x += (len(AP)+len(AM))*(N-len(AP)-len(AM))
      if N-len(AP)-len(AM) > 1:
        x += (N-len(AP)-len(AM))*(N-len(AP)-len(AM)-1)//2
    elif c == 0:
      x += len(AP)*len(AM)
    else:
      i = 0
      for j in range(len(AM)):
        while(i < len(AP) and AP[i]*AM[j] >= c):
          i += 1
        x += len(AP)-i

    #print(l,r,c,x)
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()