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

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

from fractions import Fraction

ABS=[abs(a) for a in A]
OK=-max(ABS)**2-1
NG=max(ABS)**2+1

import bisect

while NG-OK>1:
    mid=(OK+NG)//2
    SC=0
    for i in range(N):
        if A[i]>0:
            x=bisect.bisect_left(A,Fraction(mid,A[i]))
            SC+=max(0,x-i-1)

        elif A[i]<0:
            x=bisect.bisect_right(A,Fraction(mid,A[i]))
            SC+=min(N-i-1,N-x)
        else:
            if mid>0:
                SC+=N-i-1
            else:
                SC+=0

    #print(OK,NG,mid,SC)

    if SC<=K-1:
        OK=mid
    else:
        NG=mid
        
print(OK)

Submission status: Time Limit Exceeded

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

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

memo =[]

for i in range(N):
	for j in range(i+1,N):
		memo.append(A[i]*A[j])
memo.sort()
#print(memo)
print(memo[K-1])

Submission status: Time Limit Exceeded

Solution code:

from itertools import product, permutations,combinations
from collections import deque
# N,K=4, 3
# A=[3, 3, -4, -2]
N,K=map(int, input().split())
A=list(map(int, input().split()))
A=sorted(A)
A=deque(A)
output=deque()
for i in combinations(A,2):
    output.append((i[0]*i[1]))
print(sorted(output)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

combi = list(itertools.combinations(A,2))

for i in range(len(combi)):
    temp = combi[i]
    product = int(temp[0]) * int(temp[1])
    product_list = product_list + [product]

product_list = sorted(product_list)

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

Submission status: Time Limit Exceeded

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

for i in range(0,N):
  for j in range(i+1,N):
    x.append(a[i]*a[j])
x.sort()
print(x[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

def main():

    n, k = map(int,input().split()[:2])
    an = list(map(int,input().split()[:n]))
    product=[]

    for i in range(n):
        for j in range(i+1,n):
            product.append(an[i]*an[j])
    product.sort()
    print(product[k-1])

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
from operator import mul
from functools import reduce

input_int = list(map(int,input().split()))
input_line = list(map(int,input().split()))

result_list = []

result = list(itertools.combinations(input_line, 2))

for i in result:
    result_list.append(reduce(mul, i))

result_list.sort()

print(result_list[input_int[1] - 1])

Submission status: Time Limit Exceeded

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

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):
        M = A[i] * A[j] 
        bisect.insort(B,M)
print(B[K-1])

Submission status: Time Limit Exceeded

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

an = []

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

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
k = []
for x in range(len(A)):
    for j in range(x+1, len(A)):
        temp = A[x] * A[j]
        k.append(temp)

result = sorted(k)
print(result[K-1])

Submission status: Time Limit Exceeded

Solution code:
import heapq

n, k = map(int, input().split())
q = list(map(int, input().split()))
ans = []

for i in range(n):
  x = q[i]
  for j in range(i+1, n):
    ans.append(x * q[j])
print(sorted(ans)[k-1])

Submission status: Time Limit Exceeded

Solution code:
#155 d
n,k=map(int,input().split())
a=list(map(int,input().split()))
num=[]
for i in range(n-1):
    for j in range(i+1,n):
        x=a[i]*a[j]
        num.append(x)
num.sort()
print(num[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 

l = list(combinations(l, 2))
c = sorted(l, key=lambda x: x[0] * x[1])[K-1]
print(c[0] * c[1])

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
  n, k = map(int, input().split())
  a = [int(x) for x in stdin.readline().split()]
  l = []
  l_append = l.append
  for i in range(0, n):
    for j in range(i+1, n):
      l_append(a[i]*a[j])
  l.sort()
  print(l[k-1])

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = [int(x) for x in 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:
#!/usr/bin/env python3


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)

import random
from itertools import combinations
def get_val(ab):
    a,b = ab
    return a*b

def partition(vector, left, right, pivotIndex):
    pivotValue = get_val(vector[pivotIndex])
    vector[pivotIndex], vector[right] = vector[right], vector[pivotIndex]  # Move pivot to end
    storeIndex = left
    for i in range(left, right):
        if get_val(vector[i]) < pivotValue:
            vector[storeIndex], vector[i] = vector[i], vector[storeIndex]
            storeIndex += 1
    vector[right], vector[storeIndex] = vector[storeIndex], vector[right]  # Move pivot to its final place
    return storeIndex
 
def _select(vector, left, right, k):
    "Returns the k-th smallest, (k >= 0), element of vector within vector[left:right+1] inclusive."
    while True:
        pivotIndex = random.randint(left, right)     # select pivotIndex between left and right
        pivotNewIndex = partition(vector, left, right, pivotIndex)
        pivotDist = pivotNewIndex - left
        if pivotDist == k:
            return get_val(vector[pivotNewIndex])
        elif k < pivotDist:
            right = pivotNewIndex - 1
        else:
            k -= pivotDist + 1
            left = pivotNewIndex + 1
 
def select(vector, k, left=None, right=None):
    """\
    Returns the k-th smallest, (k >= 0), element of vector within vector[left:right+1].
    left, right default to (0, len(vector) - 1) if omitted
    """
    if left is None:
        left = 0
    lv1 = len(vector) - 1
    if right is None:
        right = lv1
    assert vector and k >= 0, "Either null vector or k < 0 "
    assert 0 <= left <= lv1, "left is out of range"
    assert left <= right <= lv1, "right is out of range"
    return _select(vector, left, right, k)
    

def main():
    # Failed to predict input format
    N, K = list(map(int, input().split()))
    A = list(map(int, input().split()))

    A.sort()

    lst = []

    
    combs = combinations(A, 2)
    print(select(list(combs),K-1))
    pass

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

calced_list = (numbers[i] * numbers[j] for i in range(N) for j in range(i+1, N))
        
print(sorted(calced_list)[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
ha=input('')
ha=ha.split(' ')
n=int(ha[0])
k=int(ha[1])

a=input('')
a=a.split(' ')

for b in range(n):
    a[b]=int(a[b])

mulli=[]
p=n
for i in range(n-1):
    p=p-1
    for j in range(p):
        mulli.append(a[i]*a[j+i+1])
        mulli=sorted(mulli)

if len(mulli)>=1:
    print(mulli[k-1])

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):
    if len(products) == 0:
      products.append(A[i]*A[j])
    else:
      for k in range(len(products)):
        if A[i]*A[j] >= max(products):
          products.append(A[i]*A[j])
          break
        elif A[i]*A[j] <= products[k]:
          products.insert(k, A[i]*A[j])
          break
print(products[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations,product

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

ln = [x for x in l if x<0]
lz = [x for x in l if x==0]
lp = [x for x in l if x>0]

a = len(ln)
b = len(lz)
c = len(lp)

nn = a*c
nz = int(b*(a+c) + b*(b-1)/2)
np = int(a*(a-1)/2 + c*(c-1)/2)

if k<=nn:
    resl = [x*y for x,y in product(ln,lp)]
    resl.sort()
    print(resl[k-1])
elif nn<k<=nn+nz:
    print(0)
else:
    resl = [x*y for x,y in combinations(ln,2)] + [x*y for x,y in combinations(lp,2)]
    resl.sort()
    print(resl[k-nn-nz-1])

Submission status: Time Limit Exceeded

Solution code:
import copy
N, K = map(int, input().split())
A = list(map(int, input().split()))
t=[]
for i in range(N-1):
  for j in range(N-i-1):
    t.append(A[i]*A[i+j+1])
C=sorted(t)
print(C[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])

def merge_sort(arr):
    if len(arr) <= 1:
        return arr

    mid = len(arr) // 2
    # ここで分割を行う
    left = arr[:mid]
    right = arr[mid:]

    # 再帰的に分割を行う
    left = merge_sort(left)
    right = merge_sort(right)

    # returnが返ってきたら、結合を行い、結合したものを次に渡す
    return merge(left, right)


def merge(left, right):
    merged = []
    l_i, r_i = 0, 0

    # ソート済み配列をマージするため、それぞれ左から見ていくだけで良い
    while l_i < len(left) and r_i < len(right):
        # ここで=をつけることで安定性を保っている
        if left[l_i] <= right[r_i]:
            merged.append(left[l_i])
            l_i += 1
        else:
            merged.append(right[r_i])
            r_i += 1

    # 上のwhile文のどちらかがFalseになった場合終了するため、あまりをextendする
    if l_i < len(left):
        merged.extend(left[l_i:])
    if r_i < len(right):
        merged.extend(right[r_i:])
    return merged
   
x=merge_sort(x)
print(x[n[1]-1])

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort_left

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):
        insort_left(lst, a[i] * a[j])

print(lst[k - 1])

Submission status: Time Limit Exceeded

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

from itertools import combinations as comb

ans = [x[0]*x[1] for x in comb(a, 2)]
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 numpy as np
num = np.array(a, dtype=np.int64)
ans = np.array([], dtype=np.int64)
for i in range(n-1):
    ans = np.insert(ans, 0, num[i] * num[i+1:])
ans = np.sort(ans)
print(int(ans[k-1]))

Submission status: Time Limit Exceeded

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

import itertools
times = []
for i in itertools.combinations(A, 2):
    times.append(i[0]* i[1])

times_sort = sorted(times)
print(times_sort[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
n, k  = map(int,input().split())
lis = list(map(int,input().split()))

mi_lis = []
pl_lis = []
for l in lis:
    if l < 0:
        mi_lis.append(l)
    else:
        pl_lis.append(l)
a = len(mi_lis)
b = len(pl_lis)
tmp = []
if k <= a*b:
    for m in mi_lis:
        for p in pl_lis:
            tmp.append(m*p)
    print(sorted(tmp)[k-1])
    exit()
else:
    k -= a*b
    tmp_2 = list(itertools.combinations(mi_lis, 2))
    for t2 in tmp_2:
        tmp.append(t2[0]*t2[1])
    tmp_3 = list(itertools.combinations(pl_lis, 2))
    for t3 in tmp_3:
        tmp.append(t3[0]*t3[1])
    print(sorted(tmp)[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

AA = list(itertools.combinations(A, 2))
AxA = sorted(AA, key=lambda x: x[0]*x[1])

print(AxA[K-1][0]*AxA[K-1][1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from sys import stdin


def main():
  n, k = map(int, input().split())
  a = [int(x) for x in stdin.readline().split()]
  l = []
  for i in range(0, n):
    for j in range(i+1, n):
      l.append(a[i]*a[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()) 
A = list(map(int, input().split())) 

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

S = list(itertools.combinations(A, r=2))

X = [i[0]*i[1] for i in S]
X.sort()

print(X[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

multiple_list = list(combinations(A, 2))
multiple_result_list = []
for i,j in multiple_list[:]:
	multiple_result_list.append(i*j)

result_sorted = sorted(multiple_result_list)

print(result_sorted[K-1])

Submission status: Time Limit Exceeded

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

for i in range(N):
	for j in range(N-(i+1)):
		result.append(Aj[i]*Aj[j+(i+1)])
result = sorted(result)
print(result[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

p = list(combinations(A, 2))
p.sort(key = lambda x: x[0] * x[1])
a,b = p[k-1]

print(a*b)

Submission status: Time Limit Exceeded

Solution code:
inp = list(map(int, input().split())) 
l = list(map(int, input().split()))
# print(l)

mul_num = []

for i in range(0, inp[0]):
  for j in range(i + 1, inp[0]):
    mul_num.append(l[i] * l[j])

print(sorted(mul_num)[inp[1] - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
 
a, b = map(int, input().split())
c = list(map(int, input().split()))
e = list()
for i in itertools.combinations(c, r=2):
    e.append(i[0]*i[1])
print(sorted(e)[b-1])

Submission status: Time Limit Exceeded

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

result = []

for i in range(n):
    x = a[i]
    for j in range(i+1,n):
        y = a[j]
        tmp = x*y
        num = 0
        for h in result:
            if tmp>=h:
                num+=1
            else:
                break
        result.insert(num,tmp)

print(result[k-1])

Submission status: Time Limit Exceeded

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

import itertools

lst = []
comb_dict = {}

for x, y in list(itertools.combinations(A, 2)):
    if (x, y) in comb_dict:
        lst.append(comb_dict[(x, y)])
    else:
        lst.append(x * y)
        comb_dict[(x, y)] = x * y
        
lst.sort()
print(lst[K-1])

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int, input().split())
a=[int(s) for s in input().split()]
b=[]
for i in range(n):
  for j in range(i+1,n):
    b.append(a[i]*a[j])
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()))
i=0

z=0
m=0
p=0

am=[]
ap=[]

for item in a:
    if item <0:
        m+=1
        am.append(item)
    elif item>0:
        p+=1
        ap.append(item)

#print(p,m)
plus=p*(p-1)//2+m*(m-1)//2
minus=p*m
zero=n*(n-1)//2-plus-minus

if k<=minus:
    result=[]
    for item1 in ap:
        for item2 in am:
            result.append(item1*item2)
    result.sort()
    print(result[k-1])
    exit()
elif k<=minus+zero:
    print(0)
    exit()
else:
    i=0
    result=[]
    while i<p-1:
        j=i+1
        while j<p:
            result.append(ap[i]*ap[j])
            j+=1
        i+=1
    i=0
    while i<m-1:
        j=i+1
        while j<m:
            result.append(am[i]*am[j])
            j+=1
        i+=1
    result.sort()
    #print(result,plus,minus,zero,k)
    print(result[-1-(zero+minus+plus-k)])
    exit()

Submission status: Time Limit Exceeded

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

posi = []
nega = []
for i in range(n):
    if a[i] < 0:
        nega.append(a[i])
    elif a[i] > 0:
        posi.append(a[i])

non0 = len(posi) + len(nega)
normal0 = n - non0
num_0 = normal0 * non0 + normal0*(normal0-1)//2
num_nega = len(posi) * len(nega)

if k <= num_nega:
    tmp = []
    for a1 in posi:
        for a2 in nega:
            tmp.append(a1*a2)
    tmp = sorted(tmp)
    print(tmp[k-1])
elif num_nega < k and k <= num_nega+num_0:
    print(0)
else:
    k = k - num_nega - num_0
    tmp = []
    for i in range(len(posi)):
        for j in range(i+1, len(posi)):
            tmp.append(posi[i]*posi[j])
    for i in range(len(nega)):
        for j in range(i+1, len(nega)):
            tmp.append(nega[i]*nega[j])
    tmp = sorted(tmp)
    print(tmp[k-1])

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

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

#S.sort()
#print(S[K-1])
#if K < (N*(N-1))/4:
ANS = heapq.nsmallest(K, S)
print(*ANS[-1:])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import collections

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

comb = collections.Counter(itertools.combinations(a, 2))

temp = 0
for i in sorted((tuple((x[0][0] * x[0][1], x[1])) for x in comb.items())):
    temp += i[1]
    if temp >= K:
        print(i[0])
        exit()

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
seki = []
for j in range(n-1):
    for l in range(j+1,n):
        seki.append(a[j]*a[l])
print(sorted(seki)[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:
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ls=[]
for i in range(len(A)-1):
    for j in range(i+1, len(A)):
        ls.append(A[i]*A[j])
ls.sort()
print(ls[K-1])

Submission status: Time Limit Exceeded

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

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 ** 30), 10 ** 30
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)
    
  if mid >= 0 :
    for i in range(len(p)) :
      x = mid // p[i]
      s += max(0, bisect_left(p, x + 1) - 1 - i)
    for i in range(len(m)) :
      x = mid // m[i]
      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:
N, K = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

# B = sorted(A, key=lambda x: abs(x))
# B = sorted(A)

ans = []

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

        # print(B[i], B[j], B[i] * B[j])

B = sorted(ans)
# print(B)
print(B[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()))
A=sorted(A)
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:
def main():
  import itertools
  N,K =map(int, input().split())
  A=list(map(int, input().split()))
  
  cc = list(itertools.combinations(A,2))
  B=[0]*len(cc)
  for i,v in enumerate(cc):
    B[i] = v[0]*v[1]
  c= sorted(B)
  print(c[K-1])

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

from itertools import combinations
from numpy import prod

N, K = map(int, input().split())
numbers = map(int,  input().split())
answers = []
for x in combinations(numbers, 2):
    answers.append(prod(x))
answers = sorted(answers, key=int)
print(answers[K-1])

Submission status: Time Limit Exceeded

Solution code:
a,b=map(int,input().split());d=[]
c=list(map(int,input().split()))
for i in range(a) :
    k=i+1
    while k!=a :
        p=c[i]*c[k]
        d.append(p)
        k+=1
d.sort()
print(d[b-1])

Submission status: Time Limit Exceeded

Solution code:

N, K = [int(n) for n in input().split()]
nums = [int (n) for n in input().split()]

results = []
for i in range(N-1):
  for j in range(i+1, N):
    xx = nums[i] * nums[j]
    results.append(xx)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

import itertools

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

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

seki = []
for i1, i2 in itertools.combinations(An, 2):
    seki.append(int(i1 * i2))
seki_sort = sorted(seki)
print(seki_sort[K - 1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from functools import reduce
 
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
 
C = combinations(A, 2)
print(sorted([reduce(lambda y, z: y * z, x) for x in C])[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=list(combinations(a,2))
cx=[]
for i in range(len(c)):
  cx.append(c[i][0]*c[i][1])
cx.sort()
print(cx[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


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

    C = combinations(A, 2)

    B = {}
    for v in C:
        k = v[0] * v[1]
        if k not in B:
            B[k] = 1
        else:
            B[k] += 1

    B = sorted(B.items())

    cnt = 0
    for v in B:
        cnt += v[1]
        if cnt >= K:
            print(v[0])
            return


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools                                      
import numpy as np                                    
                                                      
n, k = map(int, input().split())                      
A = [int(i) for i in input().split()]                 
A = sorted(A)                                         
AA_0 = []                                             
AA_1 = []                                             
for i, num in enumerate(A):                           
    for j in range(i+1, len(A)):                      
        AA_0.append(num)                              
        AA_1.append(A[j])                             
                                                      
                                                      
nAA_0 = np.asarray(AA_0)                              
nAA_1 = np.asarray(AA_1)                              
nAA_0 = nAA_0 * nAA_1                                 
nAA_0 = np.sort(nAA_0)                                
print(nAA_0[k-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K=map(int,input().split())
    A=list(map(int,input().split()))
    A.sort()
    A_minus,A_zero,A_plus=[],[],[]
    x=bisect_left(A,0)
    y=bisect_right(A,0)
    A_minus=A[:x]
    A_zero=A[x:y]
    A_plus=A[y:]
    if K<=len(A_minus)*len(A_plus):
        def nibutan1(ok,ng):
            while abs(ok-ng) > 1:
                mid = (ok + ng) // 2
                if solve1(mid):
                    ok = mid
                else:
                    ng = mid
            return ok
        
        def solve1(mid):
            c=0
            for x in A_minus:
                c+=len(A_plus)-bisect_left(A_plus,-(-mid//x))
            if c>=K:
                return True
            else:
                return False
        
        print(nibutan1(0,-10**18+1))
    K-=len(A_minus)*len(A_plus)
    if 0<K<=len(A_zero)*(N-len(A_zero))+(len(A_zero)*(len(A_zero)-1))//2:
        print(0)
    K-=len(A_zero)*(N-len(A_zero))+(len(A_zero)*(len(A_zero)-1))//2
    if K>0:
        def nibutan2(ok,ng):
            while abs(ok-ng) > 1:
                mid = (ok + ng) // 2
                if solve2(mid):
                    ok = mid
                else:
                    ng = mid
            return ok
        
        def solve2(mid):
            c=0
            for x in A_minus:
                c+=len(A_minus)-bisect_left(A_minus,-(-mid//x))
                if -(-mid//x)<=x:
                    c-=1
            for x in A_plus:
                c+=bisect_right(A_plus,(mid//x))
                if (mid//x)>=x:
                    c-=1
            c//=2
            if c>=K:
                return True
            else:
                return False
        
        print(nibutan2(10**18+1,0))

    
        
    

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

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])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
import functools
import operator

n,k=map(int,input().split())
a=list(map(int, input().split()))
b=[]
c=list(itertools.combinations(a,2))
for i in range(len(c)):
    b.append(functools.reduce(operator.mul, c[i]))
b.sort()
print(b[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]

calced_list = [numbers[i] * numbers[j] for i in range(N) for j in range(i+1, N)]
# for i in range(N):
#   for j in range(i+1, N):
#       calced_list.append(numbers[i] * numbers[j])
        
print(sorted(calced_list)[K-1])

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
arr=list(map(int,input().split()))
lst1=[]
lst2=[]
ln=len(arr)
for i in range(ln):
    for j in range(i+1,ln):
        r=arr[i]*arr[j]
        if(r<0):
            lst1.append(r)
        else:
            lst2.append(r)
lst1.sort()
lst2.sort()
lst=lst1+lst2
print(lst[k-1])

Submission status: Time Limit Exceeded

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

p = itertools.combinations(a, 2)
p = sorted(p, key=lambda x: x[0]*x[1])

print(p[k-1][0] * p[k-1][1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

iter = list(itertools.combinations(A, 2))

ansli = []
for x in iter:
    ansli.append(x[0]*x[1])

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