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
from bisect import bisect_left, bisect_right


TEST_INPUT = [
    """
    4 3
    3 3 -4 -2
    """,
    """
    10 40
    5 4 3 2 -1 0 0 0 0 0
    """,
    """
    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
    """
]
ANSWER = [
    "-6",
    "6",
    "448283280358331064"
]


class InputHandler:

    def __init__(self, text_lines="", is_test=False):
        self.data = list(text_lines.split("\n"))
        self.index = 0
        self.is_test = is_test

    def input(self):
        if self.is_test:
            self.index += 1
            return self.data[self.index].strip()
        else:
            return sys.stdin.readline().rstrip()


def solve(n, k, a_list):
    a_list_s = list(sorted(a_list))

    def query(a):
        res = 0

        for i in range(n - 1):
            p = a_list_s[i]
            if p > 0:
                q = (a + p - 1) // p
                res += min(n - bisect_left(a_list_s, q), n - i - 1)
            elif p == 0:
                if a <= 0:
                    res += n - i - 1
            else:
                q = a // p
                res += max(bisect_right(a_list_s, q) - (i + 1), 0)
        if res < n * (n - 1) // 2 - k + 1:
            return False
        else:
            return True

    left = - 10 ** 18 - 1
    right = 10 ** 18 + 1
    center = 0

    while right > left + 1:
        if query(center):
            left, center = center, (center + right) // 2
        else:
            center, right = (left + center) // 2, center

    return left


def input_and_solve(ih):
    n, k = map(int, ih.input().split())
    a_list = list(map(int, ih.input().split()))
    res = solve(n, k, a_list)
    return res


def main():
    ih = InputHandler()
    res = input_and_solve(ih)
    print(res)


def test():
    for test_input, ans in zip(TEST_INPUT, ANSWER):
        ih = InputHandler(test_input, True)
        res = input_and_solve(ih)
        assert str(res) == str(ans)


if __name__ == "__main__":
    test()
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import numpy as np
from itertools import combinations
c = np.array(list(combinations(A, 2)))
#print(c[c[,0]<0 & c[,1]<0])
x = c[:,0] * c[:,1]
x = sorted(x)
#x = c[c[:,0]]*c[c[:1]]
#x = np.multiply()

#print(c)
print(x[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)):
    q = max(x, y)
    p = min(x, y)
    if (q, p) in comb_dict:
        lst.append(comb_dict[(q, p)])
    else:
        a = x * y
        lst.append(a)
        if (x >= y):
            comb_dict[(x, y)] = a
        else:
            comb_dict[(y, x)] = a
        
lst.sort()
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()))

ans = []

for i,j in itertools.combinations(a, 2):
  ans.append(i*j)

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

Submission status: Time Limit Exceeded

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

cnt = n - 1
ps = []
for a in ar:
  for num in range(cnt):
    ans = a * ar[-(num + 1)]
    ps.append(ans)
  cnt -= 1

ppp = sorted(ps)
print(ppp[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

nums = []
for cmb in cmbs:
    nums.append(cmb[0]*cmb[1])

nums = tuple(nums)
nums = sorted(nums)

print(nums[K-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = [int(num) for num in input().split()]
A = [int(num) for num in input().split()]
C = []
for i, a1 in enumerate(A):
    for j, a2 in enumerate(A):
        if j <= i:
            continue
        C.append(a1 * a2)
sorted_C = sorted(C)
print(sorted_C[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(itertools.combinations(A, 2))

result = [pair[i][0] * pair[i][1] for i in range(len(pair))]
result.sort()
print(result[K-1])

Submission status: Time Limit Exceeded

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

temp = []
for i in range(n-1):
    for j in range(i+1,n):
        temp.append(data[i]*data[j])

temp.sort()

print(temp[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-1):
    for k in range(N-i-1):
      B.append(A[i]*A[i+k+1])
  B.sort()
  print(B[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()))

data = []
left = 0
right = 1

while (left < len(A) - 1):
    data.append(A[left] * A[right])
    
    if right == len(A) - 1:
        left += 1
        right = left + 1
    else :
        right += 1


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

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort
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]
    insort(ans, k)

print(ans[K - 1])

Submission status: Time Limit Exceeded

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

num = list(map(int, input().split(" ")))
multiplication_list = []
i = 0
while i < len(num):
    j = i + 1
    while j < len(num):
        multiplication_list.append(num[i] * num[j])
        j += 1
    i += 1

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = map(int, input().split())
a = list(map(int, input().split()))
# print(sorted([x * y for x, y in itertools.combinations(a, 2)])[k - 1])

nl = []

for x, y in itertools.combinations(a, 2):
    nl.append(x * y)

nl.sort()

print(nl[k-1])

Submission status: Time Limit Exceeded

Solution code:
x = list(map(int, input().split()))
numbers = list(map(int, input().split()))
 
answers = [numbers[i]*numbers[j] for i in range(x[0]) for j in range(x[0]) if i<j]

answers.sort()
print(answers[x[1]-1])

Submission status: Time Limit Exceeded

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

target = []
#print(len(source))

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

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

Submission status: Time Limit Exceeded

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

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

MAX=max(abs(A[0]),abs(A[-1]))
OK=-MAX**2-1
NG=MAX**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,-(-mid//A[i]))
            SC+=max(0,x-i-1)

        elif A[i]<0:
            x=bisect.bisect_right(A,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:
import numpy as np
from collections import Counter
import itertools

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
c_list = list(itertools.combinations(A, 2))
P = [[]]*len(c_list)
for i in range(len(c_list)):
  P[i] = c_list[i][0]*c_list[i][1]
P = sorted(P)
print(P[K-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9) #再帰用
n, k = list(map(int,(input().split())))
a = list(map(int,(input().split())))
#from heapq import heapify, heappop, heappush
import itertools
import bisect

x = []
#heapify(x)
p = itertools.combinations(a, 2)
for i in p:
  bisect.insort(x,int(i[0]*i[1]))
 
#heapify(x)
print(x[k-1])  
#print(x)

Submission status: Time Limit Exceeded

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

c=sorted([x * y for x, y in itertools.combinations(a,2)])
print(c[k-1])

Submission status: Time Limit Exceeded

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

A=list(map(int, input().split()))
B=[]
for i in range(1, N):
  for j in range(i):
    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())
As = [int(i) for i in input().split()]
new = sorted(As)

#flag = False
nums = []
for i in range(N-1):
    for j in range(i + 1, N):
        nums.append(new[i] * new[j])
        # if len(nums) == K+1:
        #   flag = True
        #   break
    # if flag:
     #   break

ans = sorted(nums)
print(ans[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(len(a)):
    for j in range(i+1,len(a)):
        c.append(a[i]*a[j])
c.sort()
print(c[K-1])
#print(c)

Submission status: Time Limit Exceeded

Solution code:
import itertools
import functools
import operator
souseki = functools.partial(functools.reduce, operator.mul)
A = list(map(int , input().split()))
B = list(map(int , input().split()))
mm = list(itertools.combinations(B, 2))
list_2 = list(map(lambda x: souseki(x), mm))
print(sorted(list_2)[A[1]-1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
zero_count = 0
sei_a_list = []
hu_a_list = []
for a in a_list:
    if a == 0:
        zero_count += 1
    elif a > 0:
        sei_a_list.append(a)
    else:
        hu_a_list.append(a)
flag = ""
hu_size = len(sei_a_list) * len(hu_a_list)
zero_size = (n * zero_count - zero_count * (zero_count + 1) // 2)

if k <= hu_size:
    flag = "hu"
elif k <= (zero_size + hu_size):
    flag = "zero"
else:
    flag = "sei"
if flag == "hu":
    hu_list = []
    for i in range(0, len(sei_a_list)):
        for j in range(0, len(hu_a_list)):
            hu_list.append(sei_a_list[i] * hu_a_list[j])
    hu_list = sorted(hu_list)
    print(hu_list[k - 1])
elif flag == "sei":
    sei_list = []
    for i in range(0, len(sei_a_list)):
        for j in range(i + 1, len(sei_a_list)):
            sei_list.append(sei_a_list[i] * sei_a_list[j])
    for i in range(0, len(hu_a_list)):
        for j in range(i + 1, len(hu_a_list)):
            sei_list.append(hu_a_list[i] * hu_a_list[j])
    sei_list = sorted(sei_list)
    print(sei_list[k - 1 - (zero_size + hu_size)])
else:
    print(0)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb =[a1*a2 for a1, a2 in itertools.combinations(A, 2)]

comb.sort()

print(comb[(NK[1]-1)])

Submission status: Time Limit Exceeded

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

for i in range(N):
    for j in range(i, N):
        if i != j:
            A_m.append(A[i]*A[j])
            
A_m_sorted = sorted(A_m)

print(A_m_sorted[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-1):
  for j in range(i+1,N):
    S.append(A[i]*A[j])
S=sorted(S)
print(S[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import operator

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

print(sorted(itertools.starmap(operator.mul, itertools.permutations(A, 2)))[K * 2 - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import sys
input = sys.stdin.readline
n, k = map(int,input().split())

a = list(map(int,input().split()))
seki = []
for v in itertools.combinations(a,2):
    seki.append(v[0]*v[1])
print(sorted(seki)[k-1])

Submission status: Time Limit Exceeded

Solution code:

#import math
import itertools

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

c_list = list(itertools.combinations(A_List, 2))
seki_list = []
for i in range(len(c_list)):
    seki = c_list[i][0] * c_list[i][1]
    seki_list.append(seki)


#print(c_list)
#print(seki_list)

seki_list.sort()

print(seki_list[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

prod_comb = []

for i in range(0, N-1):
  for j in range(i+1, N):
    prod_comb.append(data[i]*data[j])
prod_comb.sort()
print(prod_comb[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=sorted(a)
q=[]
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        #print(i,j)
        q.append(a[i]*a[j])
        
q=sorted(q)
#print(q)
print(q[k-1])

'''
l=list(itertools.combinations(a,2))
l=sorted(l,key=lambda f: f[0]*f[1])
#for i in range(len(l)):
#    print(i+1,l[i],l[i][0]*l[i][1])
#print(l)
print(l[k-1][0]*l[k-1][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-1):
    ans += map(lambda x: x*A[i], A[i+1:])
ans.sort()
print(ans[K-1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

ls = []
for i, j in itertools.combinations(arr, 2):
  ls.append(i * j)
ls.sort()
print(ls[k - 1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

Aarray = np.array(A, dtype=int)

mul_list = []
for i in range(N):
    mul_list += list(Aarray[i] * Aarray[(i+1):])

ans = sorted(mul_list)[max(K-1, 0)]
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N,K=map(int,input().split())
A=list(map(int,input().split()))
A=sorted(A)
#B=list(reversed(A))
A=np.array(A)
Aneg=A[A<0]
Azero=A[A==0]
Apos=A[A>0]

n_neg=len(Aneg)*len(Apos)
n_zero=len(Azero)*(len(Azero)-1)//2+len(Azero)*(len(Aneg)+len(Apos))
n_pos=(len(Apos)*(len(Apos)-1)+len(Aneg)*(len(Aneg)-1))//2

if K <=n_neg:
    n=K
    B=sorted(Aneg)
    C=sorted(Apos)
    ans=[]
    for i in range(len(B)):
        for j in range(len(C)):
            ans.append(B[i]*C[j])
    ans=sorted(ans)
    print(ans[n-1])
    
elif K>n_neg+n_zero:
    n=K-(n_neg+n_zero)
    B=sorted(Aneg)
    B=list(reversed(B))
    C=sorted(Apos)
    ans=[]
    if len(B)>2:
        for i in range(len(B)-1):
            for j in range(i+1,len(B)):
                ans.append(B[i]*B[j])
    if len(C)>2:
#         k=min(len(C),n-1)
        for i in range(len(C)-1):
            for j in range(i+1,len(C)):
                ans.append(C[i]*C[j])
    ans=sorted(ans)
    print(ans[n-1])
    
else:
    print(0)

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

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,-(-mid//A[i]))
            SC+=max(0,x-i-1)

        elif A[i]<0:
            x=bisect.bisect_right(A,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:
# coding: utf-8
import itertools

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

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

alist = []
for nn in cm:
    tmp = nn[0] * nn[1]
    alist.append(tmp)
alist.sort()
print(alist[k-1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!

import sys
readline = sys.stdin.readline
read = sys.stdin.read

#n,*a = [int(i) for i in read().split()]
#a = [int(i) for i in readline().split()]
#n = int(input())

def solve():
    from bisect import bisect_right, bisect_left
    
    n,k,*a = [int(i) for i in read().split()]
    a.sort()
    
    #v = [a[i]*a[j] for i in range(n) for j in range(i+1,n)]
    #v.sort()
    #print(v)
    #print(v[k-1])
    
    l = bisect_left(a,0)
    r = bisect_right(a,0)
    
    a_neg = [-i for i in a[:l][::-1]]
    a_pos = a[r:]
    
    if k <= l*(n-r): # negative
        def check(x): #x 以上は k 個以上あるか？
            res = (n-r)*len(a_neg)
            v = len(a_pos)
            for i in a_neg:
                v = bisect_left(a_pos,(x+i-1)//i,hi=v)
                res -= v
            return res >= k
    
        ok = 0
        ng = 10**18
        while ng-ok > 1:
            mid = (ok+ng)//2
            if check(mid): ok = mid
            else: ng = mid
    
        print(-ok)
    
    elif k <= n*(n-1)//2 - l*(l-1)//2 - (n-r)*(n-r-1)//2:
        print(0)
    
    else:
        k -= n*(n-1)//2 - l*(l-1)//2 - (n-r)*(n-r-1)//2
    
        def check(x): #x 以下は k 個以上あるか？
            res = 0
            vn = len(a_neg)
            for i,ai in enumerate(a_neg):
                vn = bisect_right(a_neg,x//ai,hi=vn)
                if vn > i+1: res += vn-i-1

            vp = len(a_pos)
            for i,ai in enumerate(a_pos):
                vp = bisect_right(a_pos,x//ai,hi=vp)
                if vp > i+1: res += vp-i-1
            return res >= k
        
        ng = 0
        ok = 10**18
        while ok-ng > 1:
            mid = (ok+ng)//2
            if check(mid): ok = mid
            else: ng = mid
    
        print(ok)


solve()

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
B = []
for i in range(len(A)):
    for j in range(i+1,len(A)):
        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=list(map(int,input().split()))
plus=[0]
zero=[0]
minus=[0]
for i in range(n):
    if a[i]<0:
        minus.append(a[i])
    elif a[i]==0:
       zero.append(a[i])
    else:
        plus.append(a[i])

pl=len(plus)-1
ml=len(minus)-1
zl=len(zero)-1
minus.remove(0)
zero.remove(0)
plus.remove(0)
if ml*pl<k and k<=ml*pl+zl*(ml+pl)+zl*(zl-1)/2:
    print(0)
    exit()

elif ml*pl>=k:
    plus.sort(reverse=True)
    minus.sort()
    ans=[]
    for i in range(pl):
        for j in range(ml):
            tmp=plus[i]*minus[j]
            ans.append(tmp)
    ans.sort()
    print(ans[k-1])
    exit()

else:
    bh=int(k-ml*pl-zl*(ml+pl)-zl*(zl-1)/2)
    bans=[]
    plus.sort()
    minus.sort(reverse=True)
    for i in range(ml):
        for j in range(i+1,ml):
            tmo=minus[i]*minus[j]
            bans.append(tmo)

    for i in range(pl):
        for j in range(i+1,pl):
            tmo=plus[i]*plus[j]
            bans.append(tmo)
    bans.sort()

    print(bans[bh-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools


def ACC(a_list, n):
    result_q = list()
    for a, b in itertools.combinations(a_list, 2):
        if len(result_q) == 0:
            result_q.append(a * b)
            continue
        if result_q[0] >= a * b:
            result_q = [a * b] + result_q[:]
        else:
            for enum, r in enumerate(result_q[::-1]):
                if r < a * b:
                    result_q = result_q[:n - enum] + [a * b] + result_q[n - enum:]
                    break
        if len(result_q) > n:
            del result_q[-1]
        result_q.sort()
    return result_q.pop()


def main():
    N, K = map(int, input().split(' '))
    A_list = list(map(int, input().split(' ')))
    print(ACC(A_list, K))


if __name__ == '__main__':
    main()

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

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

        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 = 10 ** 18 + 1

    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:
# -*- 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()
p=[]
m=[]
for i in a:
    if i > 0:
        p.append(i)
    else:
        m.append(i)

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 numpy as np
import itertools

N, K = input().split(" ")
aList = np.array(input().split(" "), dtype=np.int).tolist()

tempList = [a * b for a, b in itertools.combinations(aList, 2)]
tempList.sort()

print(tempList[int(K) - 1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

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

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

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

new = np.asarray([i[0] * i[1] for i in arr])

new = np.sort(new)

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

S.sort()
print(S[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()))
L = list(combinations(a,2))
ans = []
for i in range((n*(n-1)//2)):
    ans.append(L[i][0]*L[i][1])
ans = sorted(ans,reverse=False)
print(ans[k-1])

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):
	for i in range(N):
		if i+j+1 < N:
			seki.append(A[i]*A[i+j+1])

seki_new = sorted(seki)
print(seki_new[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
input_n = list(map(int, input().split()))
pair = list(itertools.combinations(input_n, 2))
res = [i[0] * i[1] for i in pair]
res.sort()
print(res[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:
def kakeru(a , alist):
    ans = []
    for i in alist:
        ans.append(a * i)
    return ans

def pairs(n , k , a):

    kakelist = []
    for i in range(n - 1):
        kakelist += kakeru(a[i] , a[i + 1:])

    kakelist.sort()

    return kakelist[k - 1]

def main():
    n , k = map(int , input().split())
    a = list(map(int,input().split()))
    print(pairs(n , k , a))

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N,K=(int(x) for x in input().split())
A=[int(x) for x in input().split()]
multi=[]
comb=int(N*(N-1)/2)
X=1

for i in range(comb):
    multi=multi+[A[i]*A[k] for k in range(X,N)]
    X+=1

multi_sort=sorted(multi)
print(multi_sort[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

p.sort()
m.sort()

ng, ok = -(10 ** 18)-1, 10 ** 18+1
while ok - ng > 1 :
  mid = (ok + ng) // 2
  s = 0
    
  if mid < 0 :
    for i in range(len(m)) :
      x = (-mid+m[i]-1) // (m[i])
      s += len(p) - bisect_left(p, x)
    
  else :
    for i in range(len(p)) :
      x = mid // p[i]
      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())

s=list(map(int,input().split()))
s2=[]
for i in range(n):
    for j in range(n):
        if i>j:
            s2.append(s[i]*s[j])
s3=sorted(s2)
print(s3[k-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


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


ans=[]


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



x.sort()


print(x[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
x = list(map(int, input().split()))
numbers = list(map(int, input().split()))
 
answers = list()
append = answers.append
for i1 in range(x[0]):
    for i2 in range(0, len(numbers)):
        if(i1 < i2):
            append(numbers[i1]*numbers[i2])
 
answers.sort()
print(answers[x[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):
    for j in range(i+1,N):
        ans.append(A[i]*A[j])
print(sorted(ans)[K-1])