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:
from itertools import combinations

a,b = input().split()
arr = list(map(int,input().split()))
les = list(combinations(arr,2))
out = [(x*y)for x,y in les]
out.sort()

print(out[int(b)-1])

Submission status: Time Limit Exceeded

Solution code:
def main():
    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:
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])
T = sorted(S)
print(T[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import product, combinations
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_pos = sorted([a for a in a_list if a > 0])
a_neg = sorted([a for a in a_list if a < 0], reverse=True)
a_zero = [a for a in a_list if a == 0]
z = len(a_zero)
if k <= len(a_pos) * len(a_neg):
    a_may = sorted([a[0] * a[1] for a in product(a_pos, a_neg)])
    print(a_may[k - 1])
elif k <= len(a_pos) * len(a_neg) + (len(a_pos) + len(a_neg)) * z + z * (z - 1) // 2:
    print(0)
else:
    d = len(a_pos) * len(a_neg) + (len(a_pos) + len(a_neg)) * z + z * (z - 1) // 2
    a_may = [a[0] * a[1] for a in combinations(a_pos, 2)]
    a_may += [a[0] * a[1] for a in combinations(a_neg, 2)]
    a_may.sort()
    print(a_may[k - d - 1])

Submission status: Time Limit Exceeded

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

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

order=[]    
heapq.heapify(B)
for _ in range(K):
  order.append(heapq.heappop(B))
  
print(order[-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

a_minus = a[a < 0]
a_0 = a[a == 0]
a_plus = a[a > 0]

num_minus = len(a_minus) * len(a_plus)
num_0 = len(a_0) * (len(a) - len(a_0)) + int(len(a_0) * (len(a_0) - 1) / 2)
 
product = []
if k <= num_minus:
  for i in range(len(a_minus)):
    for j in range(len(a_minus) + len(a_0), n):
      product.append(a[i] * a[j])
  print(sorted(product)[k - 1])
elif k <= num_minus + num_0:
  print(0)
else:
  for i in range(len(a_minus) - 1):
    for j in range(i + 1, len(a_minus)):
      product.append(a[i] * a[j])
  for i in range(len(a_minus) + len(a_0), n - 1):
    for j in range(i + 1, n):
      product.append(a[i] * a[j])
  print(sorted(product)[k - (num_minus + num_0) - 1])

Submission status: Time Limit Exceeded

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

l = []
for i in range(n-1):
    for j in range(i+1, n):
        l.append(a[i]*a[j])
l.sort()
print(l[k-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(0,n-1):
	for j in range(i,n-1):
		tem = a[i] * a[j+1]
		result.append(tem)

result.sort()

print(result[k-1])

Submission status: Time Limit Exceeded

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

a_m=[i for i in a if i<0]
a_z=[i for i in a if i==0]
a_p=[i for i in a if i>0]

a_minus=len(a_m)
a_zero=len(a_z)
a_plus=len(a_p)

ans_minus=a_minus*a_plus
ans_zero=a_zero*(a_minus+a_plus)+a_zero*(a_zero-1)//2
ans=[]
if ans_minus>=k:
    for i in range(a_minus):
        for j in range(a_plus):
            ans.append(a_m[i]*a_p[j])
    ans.sort()
    print(ans[k-1])
elif ans_zero+ans_minus>=k:
    print(0)
else:
    for i in range(a_plus):
        for j in range(a_plus):
            if i>j:
                ans.append(a_p[i]*a_p[j])
    for m in range(a_minus):
        for n in range(a_minus):
            if m>n:
                ans.append(a_m[m]*a_m[n])
    ans.sort()
    print(ans[k-1-ans_zero-ans_minus])

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = [int(e) for e in input().split()]
A = [int(e) for e in input().split()]
L = list(itertools.combinations(A, 2))
L1 = []
for i in range(len(L)):
    L1.append(L[i][0]*L[i][1])
L1.sort()
print(L1[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

A = sorted(A)

import bisect
idx0 = bisect.bisect_left(A, 0)
idx1 = bisect.bisect_left(A, 0)

A_nega = A[:idx0]
A_zero = A[idx0:idx1]
A_posi = A[idx1:]

#print(A_nega)
#print(A_zero)
#print(A_posi)

len_nega = len(A_nega)
len_zero = len(A_zero)
len_posi = len(A_posi)

target_area = ''
ans = 0

if len_nega * len_posi >= K:
  target_area = 'np'
elif len_nega * len_posi + len_zero >= K:
  target_area = 'z'
else:
  target_area = 'nn_pp'

#print(target_area)

if target_area == 'np':
  np_multiply = []
  for i in A_nega:
    for j in A_posi:
      np_multiply.append(i*j)

  np_multiply = sorted(np_multiply)
  ans = np_multiply[K-1]

elif target_area == 'z':
  ans = 0

elif target_area == 'nn_pp':
  nnpp_multiply = []
  for i in range(len_nega):
    for j in range(i+1, len_nega):
      nnpp_multiply.append(A_nega[i]*A_nega[j])
  for i in range(len_posi):
    for j in range(i+1, len_posi):
      nnpp_multiply.append(A_posi[i]*A_posi[j])

  nnpp_multiply = sorted(nnpp_multiply)

  K_rest = K - (len_nega * len_posi + len_zero)
  ans = nnpp_multiply[K_rest - 1]

print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
tuplea = tuple(map(int, input().split()))
listans = []
for n in range(N):
    num = N-n-1
    for m in range(num):
        ansnum = tuplea[n]*tuplea[n+m+1]
        listans.append(ansnum)
listans.sort()    
print(listans[K-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,raw_input().split())
a=map(int,raw_input().split())
pq=[]
import heapq
heapq.heapify(pq)
for i in range(n):
    for j in range(i+1,n):
        heapq.heappush(pq,a[i]*a[j])
print heapq.nsmallest(k,pq)[k-1]

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

multis = []
for combination in itertools.combinations(A, 2):
    multis.append(combination[0] * combination[1])
result = sorted(multis)[K - 1]
print(result)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

def c(n,k):
    return n * (n-1) / k

pair_len = c(n,2)

minus_num = len([i for i in a_list if i < 0])
plus_num = len([i for i in a_list if i > 0])
zero_num = n - minus_num - plus_num

minus_len = minus_num * plus_num
plus_len = c(minus_num,2) + c(plus_num,2)
zero_len = int(pair_len - minus_len - plus_len)

if k <= minus_len:
    #-1つ,+1つ
    minus_list = a_list[:minus_num]
    plus_list = a_list[minus_num+zero_num:]
    all_num = sorted([i*j for i in minus_list for j in plus_list])
    print(all_num[k-1])
elif k <= minus_len + zero_len:
    print(0)
else:
    #-2つ or +2つ
    minus_list = a_list[:minus_num]
    plus_list = a_list[minus_num+zero_num:]
    all_num = sorted([minus_list[i]*minus_list[j] for i in range(len(minus_list)-1) for j in range(i+1,len(minus_list))] + [plus_list[i]*plus_list[j] for i in range(len(plus_list)-1) for j in range(i+1,len(plus_list))])
    print(all_num[k-minus_len-zero_len-1])

Submission status: Time Limit Exceeded

Solution code:
A = input()
B = input()
arr1 = [int(i) for i in A.split(' ')]
arr2 = [int(i) for i in B.split(' ')]
arr3 = []
for i in range(len(arr2)-1):
	for j in range(i+1,len(arr2)):
		arr3.append(arr2[i]*arr2[j])
arr3.sort()
print(arr3[arr1[1]-1])

Submission status: Time Limit Exceeded

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

import os
import datetime

def main():
    a, b = map(int, input().split())
    val_2 = input()
    val_2_list = val_2.split()
    num_list = []

    for i in range(a):
        num_list.append(int(val_2_list[i]))

    result_dict = []

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

    min_list = sorted(result_dict)

    print(min_list[b-1])



if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

a.sort()

#for i in range(n-1):
#    if a[i]<0 and a[i+1]>=0 :
#        i0=i+1
#        break
    
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])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
L = list(map(int,input().split()))
#print(L)
M = []
def comb2(s):
    for i, v1 in enumerate(s):
        for j in range(i+1, len(s)):
            yield [v1, s[j]]
List = list(comb2(L))
for v in List:
    ans = 1
    for x in v:
        ans *= x
    M.append(ans)
#print(M)
M.sort()
print(M[K-1])

Submission status: Time Limit Exceeded

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


calc_arry = []
for i in range(N - 1):
    left_hand = A[i]
    for j in range(N):
        if j >= N:
            break
        if i >= j:
            continue
        right_hand = A[j]
        calc = left_hand * right_hand
        calc_arry.append(calc)

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

Submission status: Time Limit Exceeded

Solution code:
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])
print(sorted(s)[k-1])

Submission status: Time Limit Exceeded

Solution code:
NK = input().split()
N = int(NK[0])
K = int(NK[1])
 
AN = input().split()
AN = [int(a) for a in AN]
AN2 = [AN]*N
 
import numpy as np
AN = np.array([AN])
AN2 = np.array(AN2)
AN = AN.reshape(N,-1)
pro = AN * AN2
num = []
for i in range(N):
  for l in range(i+1):
      num.append(i*N+l)
pro2 = pro.flatten()
pro2 = np.delete(pro2, num,0)
pro2 = np.sort(pro2, kind='quick_sort')
print(pro2[K-1])

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import itertools
N, K = map(int, input().split())
A = list(map(int, input().split()))
lst = [i[0]*i[1] for i in itertools.combinations(A,2)]
lst.sort()
print(lst[K - 1])

Submission status: Time Limit Exceeded

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

ans_dict = {}
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        elif not((i, j) in ans_dict or (j, i) in ans_dict):
            ans_dict[i, j] = a_list[i]*a_list[j]

sorted_ans = sorted(ans_dict.items(), key=lambda x: x[1])
print(sorted_ans[k-1][1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

temp = [i[0] * i[1] for i in list(itertools.combinations(a,2))]
temp.sort()
print(temp[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
# n = int(input())
n, k = map(int, input().split())

doc = map(int, input().split())
ans = sorted([i for i in combinations(doc, 2)], key = lambda x: x[0] * x[1])[k-1]

print(ans[0] * ans[1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k=list(map(int,input().split()))
p=list(map(int,input().split()))
l=list(itertools.combinations(p,2))
m=[]
for i in range(int(n*(n-1)/2)):
  m.append(l[i][0]*l[i][1])
n=sorted(m)
print(n[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

minus=[]
zero=0
plus=[]

for i in s:
  if i==0:
    zero=zero+1
  elif i>0:
    plus.append(i)
  else:
    minus.append(i)

    
p=len(plus)
m=len(minus)
minus_count=p*m
if zero==0:
  zero_count=0
elif zero==1:
  zero_count=zero*(p+m)
else:
  zero_count=int(zero*(p+m)+zero*(zero-1)/2)

if k<=minus_count:
  t=[]
  for i in minus:
    for j in plus:
      t.append(i*j)
  t.sort()
  print(t[k-1])
  
elif minus_count<k<=minus_count+zero_count:
  print(0)
else:
  t=[]
  for a,b in itertools.combinations(minus,2):
    t.append(a*b)
  for a,b in itertools.combinations(plus,2):
    t.append(a*b)

  t.sort()
  print(t[k-zero_count-minus_count-1])

Submission status: Time Limit Exceeded

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

A = sorted(A)
L = []

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

L = sorted(L)

print(L[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

c = itertools.combinations(temp_list, 2)
num_list = sorted(c, key=lambda x: x[0]*x[1])

output_list = list(num_list[k-1])
print(output_list[0] * output_list[1])

Submission status: Time Limit Exceeded

Solution code:
import bisect

def updiv(x,y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1

def wantA(m):

    ret = 0

    for l in L:

        if m % l == 0:
            B = m // l
        else:
            B = m // l + 1

        ret += len(R) - bisect.bisect_left(R,B)

        if ret >= K:
            return ret

    return ret

def wantB(m):

    ret = 0

    for i in range(len(R)):

        i = len(R) - 1 - i

        if R[i] == 0:
            ret += i
            continue

        if m % R[i] == 0:
            B = m // R[i]
        else:
            B = m // R[i]
 
        ret += min(i , bisect.bisect_right(R , B))

        if ret >= K:
            return ret

    
    for i in range(len(L2)):

        i = len(L2)-1-i

        if m % L2[i] == 0:
            B = m // L2[i]
        else:
            B = m // L2[i]
 
        ret += min(i , bisect.bisect_right(L2 , B))

        if ret >= K:
            return ret

    return ret
        

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

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

L = []
L2 = []
R = [] #0以上

for i in range(N):

    if A[i] < 0:
        L.append(A[i])
        L2.append(-1 * A[i])
    else:
        R.append(A[i])

L.sort()
R.sort()
L2.sort()

if K <= len(L) * len(R):

    l = L[0] * R[-1] - 1
    r = L[-1] * R[0] + 1

    while r - l != 1:

        m = (l+r) // 2

        num = wantA(m)

        if num >= K:
            r = m
        else:
            l = m

    print (r)

else:

    l = -1
    r = 1
    if len(R) > 0:
        r = max(r , R[-1] ** 2)
    if len(L2) > 0:
        r = max(r , L2[-1] ** 2)

    K -= len(L) * len(R)

    while r-l != 1:

        m = (l+r)//2

        num = wantB(m)
        #print (m , num)


        if num >= K:
            r = m
        else:
            l = m

        #print (l,r)

    print (r)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

X = sorted(D)
print(X[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = [int(v) for v in input().strip().split()]
A = [int(v) for v in input().strip().split()]

def calc_regular(N, s, A):
    items = []
    for k1, k2 in combinations(range(N), 2):
        v = A[k1] * A[k2]
        if len(items) < s:
            items.append(v)
            items.sort()
        elif items[-1] > v:
            items.append(v)
            items.sort()
            del items[-1]
        else:
            pass
    return items[-1]


def calc_reverse(N, s, A):
    items = []
    for k1, k2 in combinations(range(N), 2):
        v = A[k1] * A[k2]
        if len(items) < s:
            items.append(v)
            items.sort(reverse=True)
        elif items[-1] <= v:
            items.append(v)
            items.sort(reverse=True)
            del items[-1]
        else:
            pass
    return items[-1]


Kmax = N * (N - 1) / 2
if Kmax / 2 >= K:
    print(calc_regular(N, K, A))
else:
    print(calc_reverse(N, Kmax - K + 1, A))

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int,input().split())
A = list(map(int,input().split()))
p = list(itertools.combinations(A,2))
answer = []
for i,j in p:
    answer.append(i*j)
answer = sorted(answer)
print(answer[K-1])

Submission status: Time Limit Exceeded

Solution code:
debug = False
def count_lower_slow(v, aa):
    r = 0
    for i in range(1, len(aa)):
        for j in range(i):
            if aa[i] * aa[j] < v:
                r += 1
    return r

def count_part(v, aa):
    r = 0
    for i in range(1, len(aa)):
        for j in [0]:
            if aa[i] * aa[j] < v:
                r += 1
    return r

def count_lower(v, aa):
    r = 0
    if debug: print('aa=', aa)
    for i in range(len(aa) - 1):
        if aa[i] < 0:
            lb = i
            ub = len(aa) - 1
            if aa[i] * aa[ub] >= v:
                continue
            while ub - lb > 1:
                if debug: print('cl lb=', lb, ',ub=', ub)
                mid = (lb + ub) // 2
                if aa[i] * aa[mid] >= v:
                    lb = mid
                else:
                    ub = mid
            if debug: print('len(aa) - ub=', len(aa) - ub )
            if debug: print('slow=', count_part(v, aa[i:]))
            r += len(aa) - ub 
        elif aa[i] == 0:
            if v > 0:
                r += len(aa) - i - 1
                if debug: print('len(aa) - i - 1=', len(aa) - i - 1)
                if debug: print('slow=', count_part(v, aa[i:]))
        else:
            lb = i + 1
            ub = len(aa)
            if aa[i] * aa[lb] >= v:
                continue
            while ub - lb > 1:
                if debug: print('cl1, lb =',lb, ',ub=', ub)
                mid = (lb + ub) // 2
                if aa[i] * aa[mid] >= v:
                    ub = mid
                else:
                    lb = mid
            r += lb - i
            if debug: print('aa[i]=', aa[i], 'lb - i=', lb - i)
            if debug: print('slow=', count_part(v, aa[i:]))
        if debug: print('aa[i]=', aa[i], ',r=', r)
    if debug: print('r=', r, 'v=', v)
    if debug: print('slow=', count_lower_slow(v, aa))
    assert r == count_lower_slow(v, aa)
    return r

n, k = [int(x) for x in input().split()]
aa = [int(x) for x in input().split()]
aa.sort()
lb = min(aa[0] * aa[1], aa[0] * aa[-1], 0)
ub = max(aa[0] * aa[1], aa[-2] * aa[-1]) + 1
if debug: print(lb, ub)
count_lower(903689534377950618, aa)
# 00001111555
#         
while ub - lb > 1:
    mid = (lb + ub) // 2
    if debug: print('count_lower(mid=', mid, ')=', count_lower(mid,aa))
    if count_lower(mid, aa) <= k - 1:
        lb = mid
    else:
        ub = mid
print(lb)

Submission status: Time Limit Exceeded

Solution code:
def main():
    N,K=map(int,input().split())
    L=list(map(int,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:
# -*- coding: utf-8 -*-
from bisect import insort
n,k=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
a=list(map(int, input().split()))  #リスト入力 「a1 a2 a3 ...」みたいな配列のような入力のとき
a.sort()

c=0
for i in a:
    if i < 0:
        c += 1
    else:
        break

p = a[c:]
m = a[:c]
pair = []
minus_count = len(p) * len(m)
if minus_count > k:
    #答えはマイナス
    for i in p:
        for j in m:
            insort(pair,i*j)
    print(pair[k-1])
    
else:
    for i in range(0,len(p)):
        for j in range(i+1,len(p)):
            insort(pair,p[i]*p[j])
    for i in range(0,len(m)):
        for j in range(i+1,len(m)):
            insort(pair,m[i]*m[j])
    print(pair[k-1-minus_count])

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import permutations, combinations, combinations_with_replacement, product

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *A = map(int, read().split())
K_ = K
comb = list(combinations(A, 2))
comb = sorted(comb, key=lambda p: p[0] * p[1])

tmp = comb[K - 1]
print(tmp[0] * tmp[1])

Submission status: Time Limit Exceeded

Solution code:
import threading
N, K = map(int, input().split())
A = [int(i) for i in input().split()]
ls=[]
ls2=[]
for i in range(len(A)-1):
    for j in range(i+1, len(A)):
        if A[i]*A[j]>0:
            ls.append(A[i]*A[j])
        else:
            ls2.append(A[i]*A[j])

t1 = threading.Thread(ls.sort())
t2 = threading.Thread(ls2.sort())
t1.start()
t2.start()
t1.join()
t2.join()
res = ls2+ls
print(res[K-1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
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 = sorted(A)
print(A2[K-1])

Submission status: Time Limit Exceeded

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

import itertools
import pprint

p = itertools.combinations(List, 2)
arr = []

for i in p:
  a = i[0] * i[1]
  arr.append(a)
  
arr.sort()

print(arr[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(" ")]

mlp = []

for i in range(0,N):
  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

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

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

seki = []

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

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


seki = sorted(seki)
cnt = 0


print(seki[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(1, n):
  for j in range(i):
    aa.append(a[i] * a[j])

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

Submission status: Time Limit Exceeded

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

import sys
import math
import heapq


debug = False

def log(text):
    if debug:
        print(text)

def parse_input(lines_as_string = None):

    global debug
    lines = []
    if lines_as_string is None:
        debug = False
        # for line in sys.stdin:
        #     lines.append(line)
        lines.append(input())
        lines.append(input())
    else:
        debug = True
        lines = [e for e in lines_as_string.split("\n")][1:-1]
    
    (n, k) = [int(e) for e in lines[0].split(" ")]
    a = [int(e) for e in lines[1].split(" ")]

    return (n, k, a)


def solve(n, k, a):

    min_val = 10000000000000000000
    max_val = -10000000000000000000

    result = []
    for i in range(n-1):
        for j in range(i+1, n):
            e = a[i] * a[j]
            heapq.heappush(result, -e)
            if len(result) > k:
                heapq.heappop(result)

    result = -heapq.heappop(result)

    return result 


def main():
    # 出力
    result = solve(*parse_input())
    if isinstance(result, list):
        for r in result:
            print("%s" % r, sep='')
    else:
        print("%s" % result, sep='')

if __name__ == '__main__':

    main()

Submission status: Time Limit Exceeded

Solution code:
n, k =(int(x) for x in input().split())
a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
num = 0

lis = []

for p in range(n):
  for q in range(p+1, n):
    lis.append(a[p]*a[q])
    #insertion_sort(lis)
    lis.sort()

print(lis[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = map(int, input().split())
l = list(map(int, input().split()))
kumiawase = itertools.combinations(l, 2)
kotae_list = list()
for x, y in kumiawase:
    kotae_list.append(x * y)

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import permutations, combinations, combinations_with_replacement, product

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

N, K, *A = map(int, read().split())
K_ = K
comb = list(combinations(A, 2))
for i, p in enumerate(comb):
    comb[i] = (min(p), max(p))
comb = sorted(comb, key=lambda p: p[0] * p[1])

tmp = comb[K - 1]
print(tmp[0] * tmp[1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
n,k = map(int,input().split())
l = list(map(int,input().split()))
ans = []
for c in itertools.combinations(l,2):
    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(' '))
nums = list(map(int, input().split(' ')))
result = []
for i in range(N):
  if nums[i] == 0:
    for k in range(i+1, N):
      result.append(0)
    continue
    
  for j in range(i+1, N):
      kake = nums[i]*nums[j]
      result.append(kake)
#print(sorted(result))
print(sorted(result)[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 itertools
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
b = []

for v in itertools.combinations(a, 2):
    b.append(v[0]*v[1])
    
b.sort()

print(b[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:]
    combi = []
    for i in range(len(poss)-1):
        for j in range(i+1, len(poss)):
            combi.append(poss[i]*poss[j])
    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=map(int, input().split())
a=list(map(int, input().split())) 
box=[]
for i in range(n):
    for j in range(i+1,n):
        box.append(a[i]*a[j])
#print(sorted(box))
print((sorted(box))[k-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])
  
print(sorted(products)[K-1])

Submission status: Time Limit Exceeded

Solution code:
s = input().split()
t = input().split()
num=int(s[0])
k=int(s[1])
arr=[]
for i in range(num):
  for j in range(num):
    if i <j:
      arr.append(int(t[i])*int(t[j]))
print(sorted(arr)[k-1])

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 = [i * j for i, j in itertools.combinations(A, 2)]

l.sort()

print(l[K - 1])