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:
N, K = map(int, input().split())
A = list(map(int, input().split()))
Am = []
n0 = 0
Ap = []
for a in A:
    if a<0: Am.append(a)
    if a==0: n0+=1
    if a>0: Ap.append(a)

Am = sorted(Am)
Ap = sorted(Ap)
    
nm = len(Am)
np = len(Ap)

Nm = nm*np
N0 = n0*(n0-1)//2 + n0*(nm+np)
Np = nm*(nm-1)//2 + np*(np-1)//2

if K<=Nm:
    # K-th product is negative
    min_ok = 0
    max_ng = -10**20
    while min_ok-max_ng>1:
        tgt = (min_ok+max_ng)//2

        k=0
        i=0
        for a in Am:
            while i<np and a*Ap[i]>tgt: i+=1
            k+=np-i

        if k>=K:
            min_ok = tgt
        else:
            max_ng = tgt
            
    print(min_ok)

elif K<=Nm+N0:
    # K-th product is zero
    print(0)

else:
    # K-th product is positive
    K-= Nm+N0
    
    Am = [-a for a in Am[::-1]]
    
    min_ok = +10**20
    max_ng = 0
    while min_ok-max_ng>1:
        tgt = (min_ok+max_ng)//2

        k=0
        i=np-1
        for j,a in enumerate(Ap):
            while i>=0 and a*Ap[i]>tgt: i-=1
            if i<=j: break
            k+=i-j
            
        i=nm-1
        for j,a in enumerate(Am):
            while i>=0 and a*Am[i]>tgt: i-=1
            if i<=j: break
            k+=i-j
            
        if k>=K:
            min_ok = tgt
        else:
            max_ng = tgt
            
    print(min_ok)

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())))
ans_list = []

for v in itertools.combinations(A, 2):
    ans_list.append(v[0] * v[1])
    
ans_list.sort()
print(ans_list[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:

def func():
    N, winInd= list( map(int,input().split()) )
    winInd-= 1
    nums = list( map(int,input().split()) )

    numWays = (N*(N-1))/2
    pairs = []
    for i, n in enumerate(nums):
        for nn in nums[i + 1:]:
            pairs.append(n*nn)
            if(len(pairs) == numWays):
                pairs.sort()
                return pairs[winInd]
    pairs.sort()
    return pairs[winInd]
print(func())

Submission status: Time Limit Exceeded

Solution code:
import itertools
import math
import sys
from collections import Counter

n, k = map(int, input().split())
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 bisect

N,K = map(int,input().split())
L=list(map(int,input().split()))
L=sorted(L)
LIST=[]
c=0
for l in range(N-1):
    t=L[l]
    if t>0:
        for i in range(l+1,N):
            n=t*L[i]
            if c<K:
                index = bisect.bisect_left(LIST, n) # 2 最も左(前)の挿入箇所が返ってきている
                LIST.insert(index, n)
                c+=1
            else:
                if(max(LIST)>n):
                    index = bisect.bisect_left(LIST, n) # 2 最も左(前)の挿入箇所が返ってきている
                    LIST.insert(index, n)
                    c+=1
                else:
                    break
    else:
        for i in range(l+1,N):
            n=t*L[i]
            if c<K:
                index = bisect.bisect_left(LIST, n) # 2 最も左(前)の挿入箇所が返ってきている
                LIST.insert(index, n)
                c+=1
            else:
                if(max(LIST)>n):
                    index = bisect.bisect_left(LIST, n) # 2 最も左(前)の挿入箇所が返ってきている
                    LIST.insert(index, n)
                    c+=1
                else:
                    continue
print(LIST[K-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

results = []

for i in range(len(A)):
  for j in range(i + 1, len(A)):
    results.append(A[i] * A[j])

results.sort()

print(results[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

firstLineRawInput = input().split()
secondLineRawInput = input().split()

number = int(firstLineRawInput[0])
smaller = int(firstLineRawInput[1])

sekiList = []

kumiawaseList = list(itertools.combinations(secondLineRawInput,2))

for n in range(len(kumiawaseList)):
    sekiList.append(int(kumiawaseList[n][0]) * int(kumiawaseList[n][1]))

sortedListF = sorted(sekiList, reverse = False)

print (sortedListF[smaller-1])

Submission status: Time Limit Exceeded

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

for p in range(N):
    if A[p] > 0:
        break
m = N-p
m_sum = p*m
p_sum = m*(m-1)//2 + p*(p-1)//2
A_m = A[:p]
A_p = A[p:]

ans = []
if K > m_sum:
    for i in range(len(A_m)):
        for j in range(i+1,len(A_m)):
            ans.append(A_m[i]*A_m[j])

    for i in range(len(A_p)):
        for j in range(i+1,len(A_p)):
            ans.append(A_p[i]*A_p[j])
    ans.sort()
    print(ans[K-m_sum-1])

else:
    for i in A_m:
        for j in A_p:
            ans.append(i*j)
    ans.sort()
    print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
# スペース区切りの整数入力
N,K = map(int, input().split())
# スペース区切りの整数をリストに入力
a = [int(x) for x in input().split()]

xlist = []
for i in range(N-1):
    for j in range(i+1,N):
        xlist.append(a[i]*a[j])

xlist.sort()

print(xlist[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = 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])
list.sort(ans)
print(ans[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 = sorted(lst)

print(lst[k - 1])

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_right
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
ng, pz = [], []
z = 0
for x in a:
    if x > 0:
        pz.append(x)
    elif x < 0:
        ng.append(-x)
    else:
        z += 1
ra = list(reversed(list(map(lambda x: -x, a))))
l, r = -10 ** 19, 10 ** 19
while r - l > 1:
    if r - l < 100:
        r
    m = (l + r) // 2
    res = 0
    if m >= 0:
        res += z * (n - 1)
    for x in ng:
        idx = bisect_right(ra, m // x)
        if idx > 0 and ra[idx - 1] >= x:
            idx -= 1
        res += idx
    for x in pz:
        idx = bisect_right(a, m // x)
        if idx > 0 and a[idx - 1] >= x:
            idx -= 1
        res += idx
    if k <= res // 2:
        r = m
    else:
        l = m
print(r)

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
n,k=map(int,input().split())
a=map(int,input().split())
print(sorted([x*y for x,y in combinations(a,2)])[k-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
from itertools import combinations

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

c_of_A = np.array(list(combinations(A, 2)))
p = np.prod(c_of_A, axis=1)
print(np.sort(p)[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()))
multi_list = []
for x, y in itertools.combinations(a, 2):
    multi_list.append(x * y)
heapq.heapify(multi_list)
for _ in range(k - 1):
    heapq.heappop(multi_list)
print(heapq.heappop(multi_list))

Submission status: Time Limit Exceeded

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

multi_list.sort()

print(multi_list[k - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
#from time import time
from itertools import combinations

def input():
    return sys.stdin.readline()[:-1]


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

#t1 = time()
#AA = sorted([i*j for i, j in combinations(A, 2)])
AA = sorted([i*j for i, j in combinations(A, 2)])
print(AA[K-1])
#t2 = time()
#print(t2-t1)

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = map(int, input().split())
a = list(map(int, input().split()))
b = itertools.combinations(a, 2)
c = []

for t in b:
    c.append(t[0] * t[1])

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

Submission status: Time Limit Exceeded

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

from itertools import combinations

from heapq import heappush, heappop

A_seki = []

for combi in combinations(A, 2):
    heappush(A_seki, combi[0]*combi[1])

for i in range(K):
    pop = heappop(A_seki)
print(pop)

Submission status: Time Limit Exceeded

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

answer=[]
import itertools
for i,v in itertools.combinations(A,2):
    answer.append(i*v)
    
answer.sort()

print(answer[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

N,K = map(int,input().split())
A = sorted(list(map(int,input().split())))
C = [i for i in A if i >= 0]
D = [i for i in A if i< 0]

minus = len(C) * len(D)

nums = []

if K <= minus:
  pairs = list(itertools.product(C,D))
  for i in range(0,len(pairs)):
    p = pairs[i][0]
    q = pairs[i][1]
    n = p * q
    nums.append(n)
  nums = sorted(nums)
  
  print(nums[K - 1])
  
else:
  pair1 = list(itertools.combinations(C,2))
  pair2 = list(itertools.combinations(D,2))
  for i in range(0,len(pair1)):
    p = pair1[i][0]
    q = pair1[i][1]
    n = p * q
    nums.append(n)
  for i in range(0,len(pair2)):
    p = pair2[i][0]
    q = pair2[i][1]
    n = p * q
    nums.append(n)
  nums = sorted(nums)
  
  print(nums[K - 1 - minus])

Submission status: Time Limit Exceeded

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

cAA = AA[:]

tlist = []

# print(AA)

for a in AA:
    cAA.remove(a)
#     print(cAA)
    for c in cAA:
        tlist.append(a*c)
        
# print(tlist)

stlist = sorted(tlist)
print(stlist[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

c = combinations(A,2)
s = sorted([p1*p2 for p1,p2 in c])
print(s[k-1])

Submission status: Time Limit Exceeded

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

  B = []
  for i in range(N):
    for j in range(N-i):
      if i==N-1-j:
        continue
      else:
        B.append(A[i]*A[N-1-j])
  c= sorted(B)
  print(c[K-1])

main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main():
  n,k = map(int, input().split())
  a = list(map(int, input().split()))
  a_c = itertools.combinations(a,2)
  a_c_l = [ac[0]*ac[1] for ac in a_c]
  a_c_l.sort()
  print(a_c_l[k-1])
  
main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import heapq

N, K = [int(n) for n in input().split()]
A = sorted([int(n) for n in input().split()])
C = [c[0]*c[1] for c in combinations(A, 2)]
heapq.heapify(C)
print(heapq.nsmallest(K, C)[-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 ):
        hq_max = max(hq_max, a1 * a2)
    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 = [int(x) for x in input().split()]

from itertools import permutations, combinations,combinations_with_replacement,product
#print(list(permutations(A)))
comb=list(combinations(A,2))
#print(comb)

#mul=[]
#for i in comb:
#  mul.append(i[0]*i[1])

mul = [i[0]*i[1] for i in comb]
  
#print(mul)
sol = sorted(mul)
#print(sol)
print(sol[K-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from bisect import insort
n,k=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
pair = []
for i in range(0,n):
    for j in range(i+1,n):
        insort(pair,a[i]*a[j])

#print(pair)
print(pair[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n_num, ordered_pos = map(int, input().split())
nums = map(int, input().split())
pairs = list(combinations(nums, 2))
pairs_products = list(map(lambda x:x[0]*x[1], pairs))
pairs_products.sort()
print(pairs_products[ordered_pos-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
def Main(N, K, A):
    P = []
    for i in range(N-1):
        for j in range(i+1, N):
            bisect.insort_left(P, A[i]*A[j])
#     print(len(P))
#     print(P)
    return P[K-1]

def main():
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    print(Main(N, K, A))
    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

l.sort()

print(l[K - 1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations 

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

  

def findPairs(lst):    
    res = [] 
    for var in combinations(lst, 2): 
        res.append((var[0] * var[1]))
    
    res.sort()
    print(res[k-1])

findPairs(list_number)

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(i+1, N):
        num_a = A[i]
        num_b = A[j]
        num = num_a * num_b
        ans.append(num)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = map(int,input().split())
listA = list(map(int,input().split()))
combis = [i for i in itertools.combinations(listA,2)]
res = []
for i in combis:
    res.append(i[0]*i[1])
res.sort()
print(res[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

N,K = map(int,input().split())
L = list(map(int,input().split()))
M = []

M = list(itertools.combinations(L, 2))

#print(M)

a = []

for i,j in M:
    a.append(i*j)
a.sort()
print(a[K-1])

Submission status: Time Limit Exceeded

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

num = list(map(int, input().split(" ")))
multiplication_list = []
for i in range(len(num)-1):
  for j in range(i+1, len(num)):
      multiplication_list.append(num[i]* num[j])
multiplication_list.sort()
print(multiplication_list[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
from collections import defaultdict
d = defaultdict(int)

n, k = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
c = itertools.combinations(a, 2)

b = []
for i in c:
  if d['{}+{}'.format(i[0], i[1])] != 0:
    b.append(d['{}+{}'.format(i[0], i[1])])
    continue
  
  b.append(i[0]*i[1])
  d['{}+{}'.format(i[0], i[1])] += i[0]*i[1]

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

products = np.partition([val*second_val for idx, val in enumerate(A) for second_val in A[idx+1:]], K-1)[K-1]
print(products)

Submission status: Time Limit Exceeded

Solution code:
I=list(map(int, input().split()))
N=I[0]
K=I[1]
A=list(map(int, input().split()))

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

ans=sorted(product_list)[K-1]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ans = []
for i in list(itertools.combinations(A, 2)):
    k = i[0] * i[1]
    ans.append(k)

aa = sorted(ans)

print(aa[K - 1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

R = list()
for i in range(len(A)):
    for j in range(i+1, len(A)):
        R.append(A[i] * A[j])

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = map(int,input().split())
a = list(map(int,input().split()))
lists = []
for i,j in itertools.combinations(a,2):
    lists.append(i*j)
lists.sort()
print(lists[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = map(int, input().split())
As = list(map(int, input().split()))
combs = list(itertools.combinations(As, 2))

multis = []
for comb in combs:
    multi = comb[0] * comb[1]
    multis.append(multi)
multis.sort()
print(multis[k-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools
N, K = map(int,input().split())
A = list(map(int,input().split()))
al = np.array(list(itertools.combinations(A, 2)),dtype=np.int64)
ans = al.prod(axis = 1)
ans.sort()
print(ans[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K = [int(num) for num in input().split(' ')]
As = [int(num) for num in input().split(' ')]

AA = sorted([a*b for a,b in itertools.combinations(As, r=2)])

print(AA[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
from functools import reduce

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

p = list(itertools.combinations(a, 2))
x = []

for i in range(n * (n - 1) // 2):
    x.append(reduce(lambda x, y: x * y, list(p[i])))
x.sort()

print(x[k-1])

Submission status: Time Limit Exceeded

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

solve()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import itertools


x = []
p = itertools.combinations(a, 2)
for i in p:
  x.append(i[0]*i[1])
 

x.sort()
print(x[k-1])  
#print(x)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
ans = []
a = [int(i) for i in input().split()]
a.sort()
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:
n = list(map(int, input().split()))
l = list(map(int, input().split()))
x=[]

for i in range(n[0]-1):
    for j in range(n[0]-i-1):
        x.append(l[i]*l[i+j+1])
x.sort()
print(x[n[1]-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

pairs = list(itertools.combinations(ns, 2))

products = []
for pair in pairs:
  products.append(pair[0]*pair[1])
  
products = sorted(products)
print(products[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()))

  A=np.array(A)
  B=[]
  for i in range(N):
    B.extend(list(A[i]*A[i+1:]))
  c= sorted(B)
  print(c[K-1])

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)
posIdx = None
for i, a in enumerate(A):
    if a >= 0:
        posIdx = i
        break
n_neg = posIdx
n_pos = len(A) - posIdx

if K <= n_neg * n_pos: # neg
    negs = []
    for n_v in A[:posIdx]:
        for p_v in A[posIdx:]:
            negs.append(n_v*p_v)
    negs = sorted(negs)
    print(negs[K-1])
else: # pos
    poss = A[posIdx:]
    poss = sorted(poss)
    # print('n_poss:', len(poss))
    combi = []
    for i in range(len(poss)-1):
        for j in range(i+1, len(poss)):
            combi.append(poss[i]*poss[j])
            # if len(combi) == (K - n_neg*n_pos):
            #     print(combi[-1])
            #     break
    for i in range(n_neg-1):
        for j in range(i+1, n_neg):
            combi.append(A[i]*A[j])
    combi = sorted(combi)
    print(combi[K-1 - n_neg*n_pos])

Submission status: Time Limit Exceeded

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

number = []

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

number.sort()

print(number[K-1])

Submission status: Time Limit Exceeded

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

# process
B = []
for i in range(N-1):
    t = A[i]
    for j in range(i+1, N):
        B.append(t*A[j])

B.sort()

# output
print(B[K-1])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = sorted(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 = sorted(li)
print(li[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

l = []

a = map(int, input().split())

for i in itertools.combinations(a, 2):
  c, d = i
  l.append(c*d)

l.sort()

print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
N,K = map(int,input().split())
arr = list(map(int,input().split()))
ans = []
for i in range(N):
  for j in range(i+1,N):
    num = arr[i]*arr[j]
    bisect.insort(ans, num)
    
print(ans[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

p = []
for x, y in list(combinations(a, 2)):
    p.append(x*y)

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

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int, input().split())
l=list(map(int, input().split()))
ansl=[]

for i in range(n):
    for j in range(n-i-1):
        ansl.append(l[i]*l[j+i+1])

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

Submission status: Time Limit Exceeded

Solution code:
import sys 

envs_input = input()
envs = envs_input.split(' ')
nums = input().split(' ')

# print(nums)

products = []
i = 0
j = 0
for a in nums:
    for b in nums[int(i+1):]:
        # print("a: ", a, " b: ", b)
        # if i != j:
        products.append(int(a) * int(b))
        j += 1
    i += 1
products_sorted = sorted(products)
# print(products)
# print(products_sorted)
print(products_sorted[int(envs[1])-1])

Submission status: Time Limit Exceeded

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

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

from itertools import combinations

combin = combinations(plist, 2)

rlist = []

from bisect import bisect_left


for comb in combin:
	prod = comb[0]*comb[1]
	i = bisect_left(rlist, prod)
	rlist.insert(i, prod)

# print(rlist)

print(rlist[k-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split()[:2])
l = list(map(int, input().split()))

from itertools import combinations 

print(sorted([a * b for a, b in list(combinations(l, 2))])[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_inv = [], []
for a1, a2 in itertools.combinations(A, 2):
    if ( len(hq) >= K ) and ( a1 * a2 >= -hq_inv[0] ):
        continue
    else:
        heapq.heappush(hq, a1 * a2)
        heapq.heappush(hq_inv, -a1 * a2)

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

Submission status: Time Limit Exceeded

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

A=np.array(A)
B=[]
for i in range(N):
  B.extend(list(A[i]*A[i+1:]))
c= sorted(B)
print(c[K-1])

Submission status: Time Limit Exceeded

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

pos = 0
answer = []
for i, x in enumerate(a):
    for y in a[i+1:]:
        now = x*y
        if pos < k:
            answer += [now]
            pos += 1
        else:
            _max = max(answer)
            if now < _max:
                answer.remove(_max)
                answer += [now]
        
print(max(answer))

Submission status: Time Limit Exceeded

Solution code:
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin

N, K = map(int,F.readline().split())
A = list(map(int,F.readline().rstrip().split()))
ans = []

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


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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

pair_list = []

xx = sorted(list(x * y for x, y in itertools.combinations(a, 2)))

print(xx[k - 1])

Submission status: Time Limit Exceeded

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

seki = []

for i in range(n):
    for j in range(i+1,n):
        seki.append(a[i]*a[j])
sorted_seki = sorted(seki)
print(sorted_seki[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product, permutations,combinations
# N,K=4, 3
# A=[3, 3, -4, -2]
N,K=map(int, input().split())
A=list(map(int, input().split()))

output=[]
for i in combinations(A,2):
    output.append(i[0]*i[1])
print(sorted(output)[K-1])

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
aa = A
answer = []
num = len(aa)
##num = aa(aa-1)/2
for i in range(num):
  for j in range(num - i - 1):
    answer.append(aa[i]*aa[i+j+1])
answer = sorted(answer)
print(answer[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k  = map(int, input().split())
arr = list(map(int, input().split()))
from itertools import combinations
comarr = []
for i in combinations(arr,2):
    comarr.append(i[0]*i[1])
comarr.sort()
print(comarr[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

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

Submission status: Time Limit Exceeded

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

l = [int(i) for i in input().split()]
l.sort()

a = sum(x<0 for x in l)
b = sum(x==0 for x in l)
c = sum(x>0 for x in l)

n = a*c + b * (a+c) + b*(b-1)//2

if k <= a*c:
  a = [i for i in l if i < 0]
  b = [i for i in l if i > 0]
  l = []
  for i in a:
    for j in b:
      l.append(i*j)
  l.sort()
  print(l[k-1])
elif a*c < k <= n:
  print('0')
else:
  a = [i for i in l if i < 0]
  b = [i for i in l if i > 0]
  l = []
  for i in range(len(a)):
    for j in range(i+1, len(a)):
      l.append(a[i]*a[j])
  for i in range(len(b)):
    for j in range(i+1, len(b)):
      l.append(b[i]*b[j])
  l.sort()
  print(l[k-1-n])

Submission status: Time Limit Exceeded

Solution code:
import itertools
n, k  = map(int,input().split())
lis = list(map(int,input().split()))
tmp = list(itertools.combinations(lis, 2))
new = []
for t in tmp:
    new.append(t[0]*t[1])
#print(sorted(new))
print(sorted(new)[k-1])

Submission status: Time Limit Exceeded

Solution code:
nk = list(map(int,input().split()))
arr_d = list(map(int,input().split()))

product = []
j = 0

for num in range(len(arr_d)-1):
  for i in range(len(arr_d)-(num+1)):
    product.append(arr_d[num] * arr_d[i+1+j])

  j += 1

product.sort()
print(product[int(nk[1])-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
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])