Problem:


Score: 400 points

Problem Statement

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?

Constraints

All values in input are integers.

2 \leq N \leq 2 \times 10^5

1 \leq K \leq \frac{N(N-1)}{2}

-10^9 \leq A_i \leq 10^9\ (1 \leq i \leq N)

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

There are six ways to form a pair. The products of those pairs are 9, -12, -6, -12, -6, 8.

Sorting those numbers in ascending order, we have -12, -12, -6, -6, 8, 9. The third number in this list is -6.

Sample Input 2

10 40
5 4 3 2 -1 0 0 0 0 0

Sample Output 2

6

Sample Input 3

30 413
-170202098 -268409015 537203564 983211703 21608710 -443999067 -937727165 -97596546 -372334013 398994917 -972141167 798607104 -949068442 -959948616 37909651 0 886627544 -20098238 0 -948955241 0 -214720580 277222296 -18897162 834475626 0 -425610555 110117526 663621752 0

Sample Output 3

448283280358331064



Sample input:
4 3
3 3 -4 -2


Sample output:
-6

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

import bisect

def main():
  n, k = map(int, input().split())
  minus = []
  zero = 0
  plus = []
  lm = 0
  lp = 0
  J = 0
  for i in map(int, input().split()):
    if i < 0:
      minus.append(-i)
      lm += 1
    elif i == 0:
      zero += 1
    else:
      plus.append(i)
      lp += 1

  minus.sort()
  plus.sort()

  J = lm*lp + zero*(n-zero) + zero*(zero-1)//2
  def test(x):
    count = 0
    if x < 0:
      x = -x
      for i in minus:
        count += lp - bisect.bisect_left(plus, -(-x//i))
      return count >= k

    if x == 0:
      return J >= k

    count = J
    for i in range(lm-1):
      t = minus[i]
      count += bisect.bisect_right(minus[i+1:], x//t)
    for i in range(lp-1):
      t = plus[i]
      count += bisect.bisect_right(plus[i+1:], x//t)
    return count >= k

  ng = -(10**18)
  ok = 10**18
  while ok-ng > 1:
    mid = (ok+ng)//2
    if test(mid):
      ok = mid
    else:
      ng = mid
  print(ok)
  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
N, K = input().split()
A = input().split()
 
N = int(N)
K = int(K)
A = list(map(int, A))
 
B = []
for i in range(N):
    for j in range(N):
        if i>j:
            B.append(A[i] * A[j])
 
B.sort()
 
print(B[K-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
  import numpy as np
  N,K =map(int, input().split())
  A=list(map(int, input().split()))
  
  B1=[]
  B2=[]
  for i in range(N):
    B1.extend([A[i]]*(N-1-i))
    B2.extend([A[i] for i in range(i+1,N)])

  B1= np.array(B1)
  B2= np.array(B2)
  B=B1*B2
  print(sorted(B)[K-1])

main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N,K = map(int, input().split())
A = list(map(int, input().split()))
k = list(combinations(A, 2))
print(sorted(list(c[0]*c[1] for c in k))[K-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))

S = [A[i]*A[j] for i in range(N)
               for j in range(i+1, N)]

print(sorted(S)[K-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int,input().split())
List = list(map(int,input().split()))
result = []
for i in range(N):
  for j in range(N- i -1):
    result.append(List[i]*List[i+j+1])
result.sort()

if K <= N*(N-1)//2:
  Answer = result[K-1]
else:
  Answer = result[-K-1]
print(Answer)

Submission status: Time Limit Exceeded

Solution code:
NK = list(map(int,input().split()))
N = NK[0]
K = NK[1]
a = list(map(int,input().split()))
ans = []
for i in range(N-1):
    for j in range(i+1, N):
        ans.append(a[i]*a[j])
ans.sort()
print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K = list(map(int, input().split()))
A = list(map(int, list(input().split())))
ans = []
for i in range(N-1):
    for j in range(N-i-1):
        ans.append(A[i]*A[i+j+1])
ans = np.sort(np.array(ans))
print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
    import sys
    input = sys.stdin.readline
    N,K=map(int,input().split())
    L=[int(x) for x in input().split()]
    LL=[L[i]*L[i+j] for i in range(0,N) for j in range(1,N-i)]
    print(sorted(LL)[K-1])
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
#from math import sqrt
from heapq import heappush, heappop
#from collections import deque

n, k = [int(v) for v in input().split()]
a = [int(v) for v in input().split()]

q = []

for i in range(n - 1):
    a1 = a[i]
    for j in range(i + 1, n):
        a2 = a[j]
        aa = a1 * a2
        heappush(q, -aa)
        if len(q) > k:
            heappop(q)

print(-heappop(q))

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np

N,K = map(int,input().split())
A = list(map(int, input().split()))
product_list = []

combi = list(itertools.combinations(A,2))
combi = np.array(combi)
product_list = combi.prod(axis=1)
product_list = np.sort(product_list)

print("%d" % product_list[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
N, K = list(map(int, input().split()))
A_N = list(map(int, input().split()))
B = []
b = 0
for i in range(N-1):
    for j in range(N-1):
        if i <= j:
            b = A_N[i] * A_N[j+1]
            B.append(b)
            b = 0
B = sorted(B)
# print(B)
print(B[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())

nums = tuple(map(int, input().split()))
cmbs = tuple(itertools.combinations(nums, 2))

hoge = (a*b for a, b in cmbs)

hoge = sorted(hoge)

print(hoge[K-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect as bs
from decimal import Decimal
N, K = map(int,input().split())
a = sorted(list(map(int,input().split())))
INF = 10**18
l = -INF
r = INF
while (r - l > 1):
    mid = (l+r)//2
    cnt = 0
    for i in range(1,N):
        if a[i-1] < 0:
            cnt += N-i-bs.bisect_left(a[i:], Decimal(mid)/a[i-1])
        elif a[i-1] > 0:
            cnt += bs.bisect_right(a[i:], Decimal(mid)/a[i-1])
        else:
            if mid >= 0:
                cnt += N-i
    if cnt < K:
        l = mid
    else:
        r = mid
    
for p in range(l+1, r+1):
    cnt = 0
    for i in range(1,N):
        if a[i-1] < 0:
            cnt += N-i-bs.bisect_left(a[i:], Decimal(p/a[i-1]))
        elif a[i-1] > 0:
            cnt += bs.bisect_right(a[i:], Decimal(p/a[i-1]))
        else:
            if p >= 0:
                cnt += N-i
    if K <= cnt:
        print(p)
        exit(0)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N, K = map(int, input().split())
A = list(map(int, input().split()))
k = list(combinations(A,2))
res = sorted(list(c[0]*c[1] for c in k))[K-1]
print(res)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import collections
import numpy as np

input1 = list(map(int,input().split()))
n = input1[0]
k = input1[1]

a = list(map(int,input().split()))
mullist = []

for i in range(len(a)-1):
    tmp = np.array(a[i+1:])
    mullist.extend(list(tmp*a[i]))

print(sorted(mullist)[k-1])

Submission status: Time Limit Exceeded

Solution code:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n,k = LI()
    a = LI()
    a.sort()
    l = -10**18-1
    r = 10**18+1
    while r-l > 1:
        m = (l+r) >> 1
        s = 0
        for i in range(n):
            ai = a[i]
            if ai == 0:
                if m >= 0:
                    s += n-i-1
            elif ai > 0:
                b = m//ai
                j = bisect.bisect_right(a,b)
                if j <= i:
                    continue
                c = j-i-1
                s += c
            else:
                b = -(m//(-ai))
                j = bisect.bisect_left(a,b)
                if j < i+1:
                    j = i+1
                c = n-j
                s += c
        if s < k:
            l = m
        else:
            r = m
    print(r)
    return

#Solve
if __name__ == "__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
N, K=map(int, input().split())
A = list(map(int, input().split()))

m=[]
for i in range(0,N):
  for n in range(0,N):
    if i>n:
      x=A[i]*A[n]
      m.append(x)

m=sorted(m)
print(m[K-1])

Submission status: Time Limit Exceeded

Solution code:
# import numpy as np
# import math
# import copy
# from collections import deque
import sys
input = sys.stdin.readline
# sys.setrecursionlimit(10000)


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

    res = []

    for i in range(N-1):
        for j in range(i+1,N):
            res.append(A[i]*A[j])

    res.sort()

    print(res[K-1])



main()

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
import heapq

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

# h = []
# for i in range(N - 1):
#     for j in range(i + 1, N):
#         heapq.heappush(h, A[i] * A[j])
# # print(h)
# # print(h[K - 1])

# count = 0
# ans = 0
# while count < K:
#     ans = heapq.heappop(h)
#     count += 1
# print(ans)

P = []
np = 0
N = []
nn = 0
nz = 0
A.sort()
for a in A:
    if a > 0:
        P.append(a)
        np += 1
    elif a < 0:
        N.append(a)
        nn += 1
    else:
        nz += 1

remain = K
# print('nn, np, nz, {}, {}, {}'.format(nn, np, nz))
if K <= nn * np:
    # print('negative')
    # K is negative
    h = []
    for p in P:
        for n in N:
            heapq.heappush(h, p * n)
    count = 0
    ans = 0
    while count < K:
        ans = heapq.heappop(h)
        count += 1
    print(ans)
    exit()
elif K <= nn * np + (nn + np) * nz + nz * (nz - 1) // 2:
    # print('zero')
    # K is zero
    print(0)
    exit()
else:
    # print('positive')
    # K is positive
    h = []
    for i in range(np - 1):
        for j in range(i + 1, np):
            heapq.heappush(h, P[i] * P[j])
    for i in range(nn - 1):
        for j in range(i + 1, nn):
            heapq.heappush(h, N[i] * N[j])
    count = nn * np + (nn + np) * nz + nz * (nz - 1) // 2
    # print(count)
    # print(h)
    ans = 0
    while count < K:
        # print(count, ans)
        ans = heapq.heappop(h)
        count += 1
    print(ans)
    exit()

Submission status: Time Limit Exceeded

Solution code:
NK = input().split(" ")
As = input().split(" ")
As = tuple(int(i) for i in As)
n = [i for i in range(len(As))]
times = [As[i]*As[x] for i in n for x in n if i > x]
times.sort()
print(times[int(NK[1])-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = [0] * 2
a = []

def format_input(filename = None):
	global n, k
	global a
	if filename == None:
		n, k = list(map(int, input().split()))
		a = list(map(int, input().split()))

	elif filename == '__random__':
		from random import randint as rng
		n = rng(2, 2 * 10**5)
		k = rng(1, (n * (n - 1)) // 2)
		a = [rng(-1 * 10**9, 10**9) for i in range(n)]

def get_answer():
	aa = []
	x = a
	while len(x) != 0:
		i = x.pop()
		for j in x:
			aa.append(i * j)
	aa.sort()
	answer = aa[k - 1]
	return answer

if __name__ == '__main__':
	format_input()

	ans = get_answer()
	print(ans)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations, product
from bisect import bisect_left
import heapq

def read():
    N, K = list(map(int, input().strip().split()))
    A = list(map(int, input().strip().split()))
    return N, K, A

def solve(N, K, A):
    hq = list()
    for p, q in combinations(A, r=2):
        heapq.heappush(hq, p * q)
    while K > 0:
        v = heapq.heappop(hq)
        K -= 1
    return v


if __name__ == '__main__':
    inputs = read()
    print("{}".format(solve(*inputs)))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())
A = list(map(int, input().split()))
count = 0
pair_list = []

for v in itertools.combinations(A, 2):
    pair_list.append(v[0]*v[1])

sorted_pl = sorted(pair_list)
print(sorted_pl[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int,input().split())
a = list(map(int,input().split()))
 
product = []
for i in range(n - 1):
  for j in range(i + 1, n):
    product.append(a[i] * a[j])
 
print(sorted(product)[k - 1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

n, w = map(int, input().split())

arr = np.asarray([int(i) for i in input().split(maxsplit=(n-1))])

arr = np.asarray(list(combinations(arr, 2)))


new = np.apply_along_axis(lambda a: a[0] * a[1], 1, arr)

new = np.sort(new)

try:
    print(new[w - 1])
except:
    exit()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K= map(int, input().split())
ns = [int(x) for x in input().split()]

products = [pair[0]*pair[1] for pair in combinations(ns, 2)]

print(sorted(products)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

kumi_list = []

for i in itertools.combinations(A, r=2):
    kumi_list.append(i)

seki_list = []

for i in kumi_list:
    seki_list.append(i[0] * i[1])

seki_list.sort()

print(seki_list[K-1])

Submission status: Time Limit Exceeded

Solution code:
def cross(L):
    ans = 1
    for x in L:
        ans = ans * x
    return ans

import sys
from itertools import combinations
input = sys.stdin.readline

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

st = []
for combi in combinations(a, r=2):
    s = cross(combi)
    st.append(s)

lis = sorted(st)

print(lis[k-1])

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
A=[int(x) for x in input().split()]
B=[]
for i in range(N):
  for j in range(i+1,N):
    B+=[A[i]*A[j]]
B=sorted(B)
print(B[K-1])

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
AA =[0,]
for i in range(N-1):
    for j in range(i+1,N):
        AA.append(A[i]*A[j])
del AA[0]
print(sorted(AA)[K-1])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int, input().split())
a = list(map(int, input().split()))

list = []
head = 0

for i in range(len(a)):
    for j in range(i+1, len(a)):
        list.append(a[i] * a[j])
list.sort()
print(list[k-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A.sort()
Nn = bisect.bisect_left(A, 0) # 負の数の数
Np = N - Nn
An = A[:Nn]
Ap = A[Nn:]
if Nn*Np >= K:  
  left = A[0]*A[-1] - 1
  right = max(A[0]**2, A[-1]**2) + 1
  while left+1 < right:
    mid = (left + right)//2
    c = 0
    res = False
    for an in An:
      idx = bisect.bisect_left(Ap, mid/an)
      c += Np - idx
      if c >= K:
        res = True
        break
    if res:
      right = mid
    else:
      left = mid
  
  ans = -10**20
  for an in An:
    idx = bisect.bisect_left(Ap, right/an)
    if idx < Np:
      ans = max(ans, Ap[idx]*an)
      if ans == right:
        break
else:
  k = K - Nn*Np
  An = [-an for an in An][::-1]
  left = -1
  right = 0
  if An:
    right = An[-1]**2 + 1
  if Ap:
    right = max(right, Ap[-1]**2+1)

  while left+1 < right:
    mid = (left + right)//2
    c = 0
    for i, an in enumerate(An, 1):
      idx = bisect.bisect_right(An, mid/an)
      if idx > i:
        c += idx - i
    
    if c >= k:
      right = mid
    else:
      for i, ap in enumerate(Ap, 1):
        if ap:
          idx = bisect.bisect_right(Ap, mid/ap)
          if idx > i:
            c += idx - i
        else:
          c += Np - i
    
    if c >= k:
      right = mid
    else:
      left = mid
  
  ans = 10**20
  for an in An:
    idx = bisect.bisect_left(An, right/an)
    if idx < Nn:
      ans = min(ans, An[idx]*an)
      if ans == right:
        break
  for ap in Ap:
    if ap:
      idx = bisect.bisect_left(Ap, right/ap)
      if idx < Np:
        ans = min(ans, Ap[idx]*ap)
        if ans == right:
          break
    else:
      if right == 0:
        ans = 0
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
[n,k]=list(map(int,input().split()))
alist=list(map(int,input().split()))
alist.sort()
hulist=[]
zero=0
seilist=[]
for i in range(n):
    if alist[i]<0:
        hulist.append(alist[i])
    elif alist[i]==0:
        zero+=1
    else:
        seilist.append(alist[i])
mainasu=len(hulist)*len(seilist)
zero=int((n-1+n-zero)*zero/2)
seki=[]
if k<=mainasu:#答えは負
    for i in range(len(hulist)):
        for j in range(len(seilist)):
            seki.append(int(hulist[i]*seilist[j]))
    seki.sort()
    ans=seki[k-1]
elif mainasu<k<=mainasu+zero:#答えはゼロ
    ans=0
else:#答えは正
    k=k-mainasu-zero
    for i in range(len(hulist)-1):
        for j in range(i+1,len(hulist)):
            seki.append(int(hulist[i]*hulist[j]))
    for i in range(len(seilist)-1):
        for j in range(i+1,len(seilist)):
            seki.append(int(seilist[i]*seilist[j]))
    seki.sort()
    ans=seki[k-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
# n, k = list(map(int, input().split()))
# a = list(map(int, input().split()))

# a.sort()
# print(a)
# total_product = int((n * (n - 1)) / 2)
# for i in range(1, n + 1):
#     if ((2 * n - i - 1) * (i / 2) >= k):
#         for j in range(1, n - i + 1):
#             i_i = i - 1
#             if((2 * n - i_i - 1) * (i_i // 2) + j == k):
#                 print(i - 1, i + j - 1)
#                 print(a[i - 1] * a[j + i - 1])

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = []
for i in range(n):
    for j in range(i + 1, n):
        ans.append(a[i] * a[j])

ans.sort()
print(ans[k - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = map(int, input().split())

nums = tuple(map(int, input().split()))
cmbs = tuple(itertools.combinations(nums, 2))

hoge = [cmb[0]*cmb[1] for cmb in cmbs]

hoge = tuple(hoge)
hoge = sorted(hoge)

print(hoge[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def check(s,A):
    N,K = map(int, s.split())
    A = [int(i) for i in A.split()]
    sei, zero, hu = [],[],[]
    
    for a in A:
        if a > 0:
            sei.append(a)
        elif a == 0:
            zero.append(a)
        else:
            hu.append(a)
    
    seihu_cnt = len(sei)*len(hu)
    zero_cnt = 0 if len(zero)==0 else len(zero)*(N-len(zero)) + combinations_count(len(zero),2)
    seki = []
    if K <= seihu_cnt:
        for i in hu:
            for j in sei:
                seki.append(i*j)
        if len(seki) > 1:
            seki.sort()
        print(seki[K-1])
    elif K <= seihu_cnt+zero_cnt:
        print(0)
    else:
        for a,b in combinations(sei, 2):
            seki.append(a*b)
        for a,b in combinations(hu, 2):
            seki.append(a*b)
        if len(seki) > 1:
            seki.sort()
        print(seki[K-1-seihu_cnt-zero_cnt])
    
s = input()
A = input()
check(s,A)

Submission status: Time Limit Exceeded

Solution code:
import numpy

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

S = [A[i]*A[j] for i in range(N)
               for j in range(i+1, N)]

#S.sort()
print(numpy.sort(S)[K-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    l = [A[i] * A[j] for i in range(N) for j in range(N) if i > j]
    l.sort()
    print(l[K-1])

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = map(int, input().split())
lis = list(map(int, input().split()))

lis3 = []
for i in list(itertools.combinations(lis, 2)):
    lis3.append(i[0] * i[1])

print(sorted(lis3)[k - 1])

Submission status: Time Limit Exceeded

Solution code:
import math
import itertools
import sys
def input():
    return sys.stdin.readline()[:-1]
N,K = map(int,input().split())
P=list(map(int,input().split()))


l=list(itertools.combinations(P, 2))


ans=[]


x=list(map(lambda x:x[0]*x[1],l))

x.sort()


print(x[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))

comb = list(itertools.combinations(a_list, 2))

ans = []
for c in comb:
    ans.append(c[0]*c[1])
ans.sort()
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
L = list(map(int, input().split()))
L2 = []
i = 0
for i in range(0,len(L)):
    for j in range(i + 1,len(L)):
        L2.append(L[i] * L[j])
L2.sort()
print(L2[k-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect

N,K = map(int,input().split())
A = list(map(int,input().split()))
B = []

for i in range(len(A)):
    for j in range(i+1, len(A)):
        x = A[i]*A[j]
        bisect.insort_left(B,x)
        
print(B[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = [int(i) for i in input().split()]
a_p, a_0, a_n = [], [], []
for ai in a:
    if ai < 0:
        a_n.append(ai)
    elif ai == 0:
        a_0.append(ai)
    else:
        a_p.append(ai)
len_p, len_0, len_n = len(a_p), len(a_0), len(a_n)
if k <= len_p * len_n:
    b = [i*j for i in a_p for j in a_n]
    b.sort()
    ans = b[k - 1]
k -= len_p * len_n
if 0 < k <= len_0 * (len_p + len_n) + ((len_0 * (len_0 - 1)) // 2):
    ans = 0
k -= (len_0 * (len_p + len_n) + ((len_0 * (len_0 - 1)) // 2))
if 0 < k:
    a_pc = a_p.copy()
    if 2 <= len_p: 
        b_1 = [ a_p[i]*a_p[j]  for i in range(len_p) for j in range(i + 1, len_p)]
    else:
        b_1 = []
    if 2 <= len_n:
        b_2 = [ a_n[i]*a_n[j] for i in range(len_n) for j in range(i + 1, len_n)]
    else:
        b_2 = []
    b = b_1 + b_2
    b.sort()
    ans = b[k - 1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

n,k=map(int,input().split())
A=sorted(list(map(int,input().split())))

negs=[]
poss=[]
zers=[]
for i in range(n):
    if A[i]<0:
        negs.append(A[i])
    elif A[i]>0:
        poss.append(A[i])
    else: zers.append(A[i])

pairedpos=len(negs)*(len(negs)-1)/2+len(poss)*(len(poss)-1)/2
pairedneg=len(negs)*len(poss)
pairedzero=(len(negs)+len(poss))*len(zers)+len(zers)*(len(zers)-1)/2

ans=0
flg=0
if k<=pairedneg:
    flg=1
elif pairedneg<k<=pairedneg+pairedzero:
    ans=0
else: flg=2 

if flg==1:
    higher=0
    lower=-(1e+9)**2+1
    while abs(higher-lower)>1:
        cnt=0
        mid=int((higher+lower)//2)
        for i in range(len(poss)):
            idx=bisect.bisect_left(negs, -(-mid//poss[i]))
            cnt+=idx
        if cnt<=k-1:
            lower=mid
        else:
            higher=mid
    ans=lower

elif flg==2:
    lower=0
    higher=(1e+9)**2+1
    newnegs=[-negs[i] for i in range(len(negs))]
    newnegs=sorted(newnegs)
    while abs(higher-lower)>1:
        cnt=0
        mid=int((higher+lower)//2)
        for i in range(len(newnegs)):
            idx1=bisect.bisect_left(newnegs[i+1:], -(-mid//newnegs[i]))
            cnt+=idx1
        for j in range(len(poss)):
            idx2=bisect.bisect_left(poss[j+1:], -(-mid//poss[j]))
            cnt+=idx2
        if cnt<=(k-pairedneg-pairedzero)-1:
            lower=mid
        else:
            higher=mid
    ans=lower
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
pair = itertools.combinations(map(int, input().split()), 2)
res = [i[0] * i[1] for i in pair]
res.sort()
if len(res) != 0:
    print(res[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
mula = []
for i in range(n-1):
    for j in range(i+1, n):
        mula.append(a[i]*a[j])

#print(mula)
smula = sorted(mula)
#print(smula)
print(smula[k-1])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = [int(i) for i in input().split()]
lst = []
for i in range(n-1):
    for j in range(i+1,n):
        lst.append(a[i]*a[j])

lst.sort()
print(lst[k-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

minus = []
zeros = 0
plus = []

A = list(map(int, input().split()))

for a in A:
  if a < 0:
    bisect.insort(minus, a)
  elif a == 0:
    zeros += 1
  else:
    bisect.insort(plus, a)

ret = []

size = 0

comb = len(minus) * len(plus)
comb2 = comb + zeros * (len(minus) + len(plus)) + (zeros * (zeros - 1) // 2)

if K <= comb:
  for i in range(len(minus)):
    for j in range(len(plus)):
      bisect.insort(ret, minus[i] * plus[j])
  print(ret[K - 1])
elif K <= comb2:
  print(0)
else:
  for i in range(len(minus) - 1):
    for j in range(i + 1, len(minus)):
      bisect.insort(ret, minus[i] * minus[j])
  for i in range(len(plus) - 1):
    for j in range(i + 1, len(plus)):
      bisect.insort(ret, plus[i] * plus[j])
  print(ret[K - comb2 - 1])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
from bisect import bisect_left

N, K = map(int, input().split())
A = [int(i) for i in input().split()]

p = []
m = []
zero = 0
for i in range(N) :
  if A[i] > 0 :
    p.append(A[i])
  elif A[i] < 0 :
    m.append(-A[i])
  else :
    zero += 1

p.sort()
m.sort()

ng, ok = -(10 ** 18)-1, 10 ** 18+1
while ok - ng > 1 :
  mid = (ok + ng) // 2
  s = 0 
  if mid < 0 :
    for i in range(len(m)) :
      x = (-mid+m[i]-1) // (m[i])
      s += len(p) - bisect_left(p, x)
    
  else :
    for i in range(len(p)) :
      x = mid // p[i]
      if x < p[i] : break
      s += max(0, bisect_left(p, x + 1) - 1 - i)
    for i in range(len(m)) :
      x = mid // m[i]
      if x < m[i] : break
      s += max(0, bisect_left(m, x + 1) - 1 - i)
    s += (len(p) + len(m)) * zero
    s += len(p) * len(m)
    s += zero * (zero - 1) // 2
  
  if s < K :
    ng = mid
  else :
    ok = mid
    
print(ok)

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = []

v = list(itertools.combinations(a, 2))

for i in v:
    b.append(i[0]*i[1])
    
b.sort()

print(b[k-1])

Submission status: Time Limit Exceeded

Solution code:
k=int(input().split()[1])
source = [int(i) for i in input().split()]

target = []
nagasa=len(source)

for j in range(0,nagasa):
    num=source[j]
    for i in range(j+1, nagasa):
    #for i in range(0, len(sorted_source)):
        target.append(num*source[i])

#sorted_target=list(reversed(sorted(target)))
#print(target)
sorted_target=sorted(target)
#print(sorted_target)
print(sorted_target[k-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

N, K = map(int, input().split())
a = list(map(int, input().split()))
a = list(itertools.combinations(a, 2))
L = []
for i in a:
  L.append(i[0] * i[1])
print(sorted(L)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import numpy as np
N,K = [int(e) for e in input().split()]
A = [int(e) for e in input().split()]
L = list(itertools.combinations(A, 2))
L1 = np.prod(np.array(L), axis = 1)
L1.sort()
print(L1[K-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
N, K = map(int, input().split())
A = list(map(int, input().split()))

l = []
for i in range(N):
    for j in range(i + 1, N):
        l.append(A[i]*A[j])


print(sorted(l)[K-1])

Submission status: Time Limit Exceeded

Solution code:
N,K=map(int,input().split())
L=[int(x) for x in input().split()]
LL=[L[i]*L[i+j] for i in range(0,N) for j in range(1,N-i)]
print(sorted(LL)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy
N, K = map(int, input().split())
P = list(map(int, input().split()))

A = []
for i in range (N):
    for j in range (i):
        A.append(P[i]*P[j])
                      
A2 = numpy.sort(A)
print(A2[K-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(i) for i in input().split(" ")]
lst = [int(i) for i in input().split(" ")]

lst.sort()
mlp = []

temp = 0
i=0

while K > temp:
  temp += N-i-1  
  i += 1
  
for i in range(0,temp):
  for j in range(i+1,N):
    mlp.append(lst[i]*lst[j])
        
mlp.sort()
print(mlp[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import heapq

N, K = map(int, input().split())
A = list(map(int, input().split()))
hq = []
hq_max = 0

for a1, a2 in itertools.combinations(A, 2):
    if ( len(hq) >= K ) and ( a1 * a2 >= hq_max ):
        continue
    else:
        heapq.heappush(hq, a1 * a2)
        hq_max = max(hq_max, a1 * a2)

for i in range(K):
    res = heapq.heappop(hq)
print(res)

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
a=list(map(int, input().split()))
li=[]
for i in range(n):
  for j in range(i+1,n):
    li.append(a[i]*a[j])
li.sort()
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

import bisect

def main():
  n, k = map(int, input().split())
  minus = []
  zero = 0
  plus = []
  lm = 0
  lp = 0
  for i in map(int, input().split()):
    if i < 0:
      minus.append(-i)
      lm += 1
    elif i == 0:
      zero += 1
    else:
      plus.append(i)
      lp += 1

  minus.sort()
  plus.sort()

  def test(x):
    count = 0
    if x < 0:
      x = -x
      for i in minus:
        count += lp - bisect.bisect_left(plus, -(-x//i))
      return count >= k

    if x == 0:
      count = lm*lp
      return count + zero*(n-zero) + zero*(zero-1)//2 >= k

    count = lm*lp + zero*(n-zero) + zero*(zero-1)//2
    for i in range(lm-1):
      t = minus[i]
      count += bisect.bisect_right(minus[i+1:], x//t)
    for i in range(lp-1):
      t = plus[i]
      count += bisect.bisect_right(plus[i+1:], x//t)
    return count >= k

  ng = -(10**18)
  ok = 10**18
  while ok-ng > 1:
    mid = (ok+ng)//2
    if test(mid):
      ok = mid
    else:
      ng = mid
  print(ok)
  
if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools

n,k = map(int, input().split())
a = list(map(int,input().split()))

cm = list(itertools.combinations(a, 2))
alist = []
for nn in cm:
    tmp = nn[0] * nn[1]
    alist.append(tmp)
alist.sort()

print(alist[k-1])