Problem:


Score: 400 points

Problem Statement

We have N integers A_1, A_2, ..., A_N.

There are \frac{N(N-1)}{2} ways to choose two of them and form a pair. If we compute the product of each of those pairs and sort the results in ascending order, what will be the K-th number in that list?

Constraints

All values in input are integers.

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

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

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

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

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

Sample Input 2

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

Sample Output 2

6

Sample Input 3

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

Sample Output 3

448283280358331064



Sample input:
4 3
3 3 -4 -2


Sample output:
-6

Submission status: Time Limit Exceeded

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

def merge(l,r):
    merged = []
    i, j = 0,0
    end = 'e'
    l += [end]
    r += [end]
    for _ in range(len(l) + len(r) - 2):
        if r[j] == end:
            merged.append(l[i])
            i += 1
        elif l[i] == end:
            merged.append(r[j])
            j += 1
        elif l[i] <= r[j]:
            merged.append(l[i])
            i += 1
        else:
            merged.append(r[j])
            j += 1
    return merged

def sorting(p_l):
    if len(p_l) >= 2:
        p_l1 = p_l[:len(p_l)//2]
        p_l2 = p_l[len(p_l)//2:]
        return merge(sorting(p_l1), sorting(p_l2))
    else:
        return p_l

a_l = [int(x) for x in input().split(' ')]

a_l_tmp = []
p_l_sorted = []
for a in a_l:
    p_l_tmp = list(map(lambda x:a*x, a_l_tmp))
    a_l_tmp.append(a)
    # print(p_l_tmp)
    p_l_sorted = merge(p_l_sorted, sorting(p_l_tmp))

# print(p_l_sorted)
print(p_l_sorted[K-1])

Submission status: Time Limit Exceeded

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

def judge(config , info):
    config = config.split()
    num_range = int(config[0])
    num_answear = int(config[1])
    
    info = info.split()
    
    num_dict = {}
    list_number = 0
    for num in info:
        list_number = list_number + 1
        num_dict[list_number] = int(num)
        
    result_list = []
    comb_list = list(itertools.combinations(num_dict,2))
    for num in comb_list:
        result = num_dict[num[0]] * num_dict[num[1]]
        result_list.append(result)
    
    result_list = sorted(result_list)
    
    print(result_list[num_answear-1])

def main():
    config_num = input()
    info_num = input()
    judge(config_num,info_num)

if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
from bisect import bisect_left, bisect_right

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

neg_end = bisect_left(A, 0)
pos_start = bisect_right(A, 0)
n_pos = N - pos_start
n_neg = neg_end
n_zero = N - (n_pos + n_neg)

n_prod_neg = n_pos * n_neg
n_prod_zero = n_zero * (n_pos + n_neg) + (n_zero * (n_zero - 1) // 2)

if K <= n_prod_neg: # answer is negative
    # binary search
    def cond(x):
        # two pointers technique
        counter = 0; r = pos_start
        for l in range(neg_end): # (A[l] * A[r] > x) -> (A[l+1] * A[r] > x)
            while r < N and A[l] * A[r] > x: r += 1
            counter += n_pos - (r - pos_start) # (A[l] * A[r] <= x) -> (A[l] * A[r+1] <= x)
        return counter >= K
    MAX = 0
    MIN = -10**18
    left, right = MIN, MAX # search range
    while right - left > 1:
        mid = (left + right) // 2
        if cond(mid): right = mid
        else: left = mid
    print(right)
elif K <= n_prod_neg + n_prod_zero: # answer is zero
    print(0)
else: # answer is positive
    K -= n_prod_neg + n_prod_zero
    # binary search
    def cond(x):
        # two pointers technique
        counter = 0
        r = N - 1
        for l in range(pos_start, N): # (A[l] * A[r] > x) -> (A[l+1] * A[r] > x)  (l < r)
            while l < r and A[l] * A[r] > x: r -= 1
            counter += max(0, r - l) # (A[l] * A[r] <= x) -> (A[l] * A[r-1] <= x)  (l + 1 < r)
            if l >= r: break
        l = 0
        for r in range(neg_end - 1, -1, -1): # (A[l] * A[r] > x) -> (A[l] * A[r-1] > x)  (l < r)
            while l < r and A[l] * A[r] > x: l += 1
            counter += max(0, r - l) # (A[l] * A[r] <= x) -> (A[l+1] * A[r] <= x)  (l < r - 1)
            if l >= r: break
        return counter >= K
    MAX = 10**18
    MIN = 0
    left, right = MIN, MAX # search range
    while right - left > 1:
        mid = (left + right) // 2
        if cond(mid): right = mid
        else: left = mid
    print(right)

Submission status: Time Limit Exceeded

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

A = list(map(int,input().split(' ')))
A.sort()
'''
N = 10
K = 25
A = [i+1 for i in range(10)]
'''

'''
N = 8
K = 3
A = [-4,-2,0,2,3,5,7,9]
'''
#[-4, -2, 0, 2, 3, 5, 7, 9]
#[-36, -28, -20, -18, -14, -12, -10, -8, -6, -4, 
# 0, 0, 0, 0, 0, 0, 0, 6, 8, 10, 
# 14, 15, 18, 21, 27, 35, 45, 63]

'''
left = -10**(18)-1
right = 10**(18)+1
left = -100
right = 100
'''
left = -(10**(18))-1
right = 10**(18)+1

def search(l,r,key):
    mid = l
    i = l-1
    index = l-1
    flag = True
    if A[i] < 0:
        flag = False
        index = N
    while(r-l>=0):
        mid = (r+l)//2
        temp = A[i]*A[mid]
        #print(f'mid{mid} temp{temp}, l-r:{l} {r}')
        if temp < key:
            index = mid
            if flag:
                l = mid+1
            else:
                r = mid-1
        else:
            if flag:
                r = mid -1
            else:
                l = mid+1
    return index

def count(key):
    cnt = 0
    for i in range(N-1):
        temp = search(i+1,N-1,key)
        if A[i]>=0:
            diff = temp - i
        else:
            diff = N - temp
        #print(f'A[i]::{A[i]}')
        #print(f'i:{i} diff{diff}')
        cnt+= diff
    #print(f'key:{key} cnt:{cnt}')
    #print()
    return cnt

ans = 0
while (right-left>=0):
    mid = (right+left)//2
    if count(mid)<K:
        left = mid+1
        ans = mid
        #print('ans:{ans}')
    else:
        right = mid-1

print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
#156d
import itertools

n,k=map(int,input().split())
a=[int(i) for i in input().split()]
num=[]
for i in itertools.combinations(a,2):
	num.append(i[0]*i[1])
num.sort()
print(num[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import product, combinations, chain


def solve(string):
    n, k, *a = map(int, string.split())
    neg = [_a for _a in a if _a < 0]
    pos = [_a for _a in a if _a > 0]
    ln, lp = len(neg), len(pos)
    lz = n - ln - lp
    if k <= ln * lp:
        l = sorted(_n * _p for _n, _p in product(neg, pos))
        return str(l[k - 1])
    k -= ln * lp
    if k <= lz * n - lz * (1 + lz) // 2:
        return "0"
    k -= lz * n - lz * (1 + lz) // 2
    l = sorted([a * b for a, b in chain(combinations(neg, 2), combinations(pos, 2))])
    return str(l[k - 1])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Time Limit Exceeded

Solution code:
def solve(string):
    n, k, *a = map(int, string.split())
    p = sorted([b * c for i, b in enumerate(a) for c in a[i + 1:]])
    return str(p[k - 1])


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np


n, k = (int(x) for x in input().split())
arr_ori = np.array(list(int(x) for x in input().split()))
mul = []

def m(arr):
    list_len = len(arr)
    for cnt in range(list_len - 1):
        arr2 = arr[cnt + 1:] * arr[cnt]
        mul.extend(arr2.tolist())


m(arr_ori)
arr = np.array(mul)
arr = np.sort(arr)
print(arr[k - 1])

Submission status: Time Limit Exceeded

Solution code:

import time
import numpy as np

start_time = time.time()

n, k = (int(x) for x in input().split())
arr_ori = np.array(list(int(x) for x in input().split()))


mul_list = []


plus_arr = np.array(arr_ori[arr_ori > 0], dtype=np.int64)
zero_arr = np.array(arr_ori[arr_ori == 0], dtype=np.int64)
minus_arr = np.array(arr_ori[arr_ori < 0], dtype=np.int64)


def mul_n(n):
    return n * (n - 1) / 2


def mul_plus(arr):
    list_len = len(arr)
    for cnt in range(list_len - 1):
        arr2 = arr[cnt + 1:] * arr[cnt]
        mul_list.extend(arr2.tolist())


def mul_minus(arr1, arr2):
    if(len(arr1) >= len(arr2)):
        max_arr = arr1
        min_arr = arr2
    else:
        max_arr = arr2
        min_arr = arr1
    min_len = len(min_arr)
    for cnt in range(min_len):
        arr = max_arr * min_arr[cnt]
        mul_list.extend(arr.tolist())


z_len = len(zero_arr)
p_len = len(plus_arr)
m_len = len(minus_arr)


num_0 = int(z_len * (p_len + m_len) + mul_n(z_len))
num_minus = int(p_len * m_len)
num_plus = int((mul_n(p_len) + mul_n(m_len)))


if(k <= num_minus):
    mul_minus(plus_arr, minus_arr)
    arr = np.sort(mul_list)
    print(arr[k - 1])

elif(k <= num_minus + num_0):
    print(0)

else:
    mul_plus(minus_arr)
    mul_plus(plus_arr)
    arr = np.sort(mul_list)
    print(arr[k - (num_0 + num_minus) - 1])

Submission status: Time Limit Exceeded

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

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

lll=sorted(ll)
print(lll[k-1])

Submission status: Time Limit Exceeded

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

# process/output

# マイナス、プラスに分類
Am = []
Ap = []
zeroNum = 0
for i in range(N):
    if A[i] < 0:
        Am.append(A[i])
    elif A[i] > 0:
        Ap.append(A[i])

# Kの数値で分岐し、結果を出力
B = []
mNum = len(Am)*len(Ap)
zNum = (N-len(Am)-len(Ap))*(N+len(Am)+len(Ap)-1)//2
if K <= mNum:
    for i in range(len(Am)):
        for j in range(len(Ap)):
            B.append(Am[i]*Ap[j])
    B.sort()
    print(B[K-1])

elif K <= mNum+zNum:
    print(0)

else:
    for i in range(len(Am)-1):
        for j in range(i+1, len(Am)):
            B.append(Am[i]*Am[j])

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

    B.sort()
    print(B[K-mNum-zNum-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import numpy as np

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

b = list(combinations(a, 2))
c = np.array(b, np.int64)
c = c.prod(axis=1)
c.sort()
print(c[k-1])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
num = [int(x) for x in input().split()]
count = 1
total = list()
for a in num:
    for i in range(n):
        if (n>i+count):
            total.append(a*num[i+count])
        else:
            break
    count +=1
total.sort()
print(total[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(i+1,n):
        x = a[i]*a[j]
        sec.append(x)

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

Submission status: Time Limit Exceeded

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

a_index_pair = []
pair_lst = []
mul_lst = []
for i in range(n):
    for j in range(n):
        if i == j:
            continue
        a_index_pair = sorted((i, j))
        if a_index_pair in pair_lst:
            continue
        pair_lst.append(a_index_pair)
        a_mul = a[i] * a[j]
        mul_lst.append(a_mul)

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math as m

def main(**kwargs):
    A.sort()
    rs = []

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

        rs.sort()
        
    r = rs[k-1]
    return r

if __name__ == "__main__":
    cin = np.array(input().split(" ")).astype("int")
    n, k, *_ = cin

    cin = np.array(input().split(" ")).astype("int")
    A = np.array(cin)
    
    cout = main(n=n, k=k, A=A)
    print(cout)

Submission status: Time Limit Exceeded

Solution code:
A = input().split()
N = int(A[0])
K = int(A[1])
L = list(map(int,input().split()))
seki = []
for a in range(N):
    for b in range((a + 1), N):
        x = L[a] * L[b]
        seki.append(x)
seki.sort()
print(seki[(K -1)])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

a,b=map(int,input().split())
c=np.array(input().split()).astype(int)
cc=list(itertools.combinations(c,2))
dd=np.prod(cc,1)
s_dd=np.sort(dd)
print(int(s_dd[b-1]))

Submission status: Time Limit Exceeded

Solution code:
#abc_155_d
#versions of not using numpy
n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
#a = np.array(a)
a.sort()

left = -10**18
right = 10**18

while left+1 < right:
    mid = (left+right)//2
    cnt = 0
    
    #run about each element as the first choice
    for i in range(n):
        #count possible pairs that satisfies the condition      
        if(a[i] >= 0):
            #hold the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    l = m
                else:
                    r = m
            
            cnt += l+1
        
        if(a[i] < 0):
            #reverse the sorted order
            l = -1 
            r = n
            while l+1<r:
                m = (l+r)//2
                if(a[i]*a[m] <= mid):
                    r = m
                else:
                    l = m
                    
            cnt += n - r
        
        if(a[i]**2 <= mid):
            cnt -= 1
        
    cnt /= 2
        
            
    
    """
    if mid >=0:
        cnt += len(zero) * n
    
    cnt += a.searchsorted(mid//plus, side="right").sum()
    cnt += (n - a.searchsorted(-(-mid//minus), side="left")).sum()
    cnt -= np.count_nonzero(a*a <= mid)
    cnt /= 2
    """
    
    if cnt >= k:
        right = mid
    if cnt < k:
        left=mid
   
        
print(right)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def pairs(k, a_list):
  ans_list = []
  pair_list = list(itertools.combinations(a_list, 2))
  for pair in pair_list:
    ans_list.append(pair[0]*pair[1])
  ans_list.sort()
  return ans_list[k-1]

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

print(pairs(k, a_list))

Submission status: Time Limit Exceeded

Solution code:

import sys
def f(A):
    B=[]
    for a in range(len(A)):
        for b in range(len(A)):
            if a>=b:
                continue
            else:
                B.append(A[a]*A[b])
        B.sort()
    return B


input=sys.stdin.readline
n,k=map(int,input().split())
L=list(map(int,input().split()))
print(f(L)[k-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

def f(A):
    B=[]
    for a in A:
        a=str(a)
        B.append(eval(a.replace(",","*")))
        B.sort()
    return B

input=sys.stdin.readline
n,k=map(int,input().split())
L=list(map(int,input().split()))
L1=list(combinations(L,2))
print(f(L1)[k-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import heapq
a = []
heapq.heapify(a)  # リストを優先度付きキューへ
N,K = map(int,input().split())
A_s = list(map(int,input().split()))

for i in range(N-1):
    for j in range(i+1,N):
        heapq.heappush(a, A_s[i]*A_s[j])
        
for i in range(K-1):
    heapq.heappop(a)

print(heapq.heappop(a))

Submission status: Time Limit Exceeded

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

def pos_serch(target):
    result = []
    for i in range(len(target)):
        for j in range(i):
            result.append(target[i] * target[j])
    return sorted(result)

def neg_serch(target1, target2):
    result = []
    for t1 in target1:
        for t2 in target2:
            result.append(t1*t2)
    return sorted(result)

def test2():
    neg_list = [i for i in a_n if i < 0]
    pos_list = [i for i in a_n if i > 0]
    zero = sum(x==0 for x in a_n)
    neg_count = len(neg_list)
    pos_count = len(pos_list)

    neg_pair = neg_count * pos_count
    pos_pair = int(pos_count*(pos_count-1)/2 + neg_count*(neg_count-1)/2)
    zero_pair = int(n*(n-1)/2 -neg_pair -pos_pair)
    if k <= neg_pair:
        print(neg_serch(neg_list, pos_list)[k-1])
    elif k <= neg_pair + zero_pair:
        print(0)
    else:
        result = pos_serch(pos_list) + pos_serch(neg_list)
        print(sorted(result)[k-1-neg_pair -zero_pair])
test2()

Submission status: Time Limit Exceeded

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

mul = []

for idx1, i in enumerate(A):
    for idx2, j in enumerate(A):
        if idx1 < idx2:
            mul.append(i*j)

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

Submission status: Time Limit Exceeded

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

result = []
for i in range(n):
    for j in range(i):
        result.append(a_n[i] * a_n[j])
print(sorted(result)[k-1])

Submission status: Time Limit Exceeded

Solution code:
def ok(n, k, a, x):
    total = 0
    for i in range(n):
        if a[i] < 0:
            l = -1
            r = n
            while l + 1 < r:
                m = (l + r) // 2
                if a[m] * a[i] < x:
                    r = m
                else:
                    l = m
            total += n - r
        else:
            l = -1
            r = n
            while l + 1 < r:
                m = (l + r) // 2
                if a[m] * a[i] < x:
                    l = m
                else:
                    r = m
            total += r
        
        if a[i] * a[i] < x:
            total -= 1
    total //= 2
    return total < k


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

A.sort()

INF = int(1e+18) + 1
l = -INF
r = INF
while l + 1 < r:
    x = (l + r) // 2
    if ok(N, K, A, x):
        l = x
    else:
        r = x

print(l)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def ok(n, k, a, x):
    total = 0
    for i in range(n):
        if a[i] < 0:
            l = -1
            r = n
            while l + 1 < r:
                m = (l + r) // 2
                if a[m] * a[i] < x:
                    r = m
                else:
                    l = m
            total += n - r
        else:
            l = -1
            r = n
            while l + 1 < r:
                m = (l + r) // 2
                if a[m] * a[i] < x:
                    l = m
                else:
                    r = m
            total += r
        
        if a[i] * a[i] < x:
            total -= 1
    total //= 2
    return total < k
    

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

A.sort()

INF = int(1e+18) + 1
l = -INF
r = INF
while l + 1 < r:
    x = (l + r) // 2
    if ok(N, K, A, x):
        l = x
    else:
        r = x

print(l)

Submission status: Time Limit Exceeded

Solution code:
import itertools
def calculate_multiple(alist, K):
  resultlist=[]
  for i in itertools.combinations(alist,2):
    resultlist.append(i[0]*i[1])
  resultlist.sort()
  return resultlist

def main():
  N, K= input().split()
  A = input().split()
  K = int(K)
  alist = [int(s) for s in A]
  resultlist=calculate_multiple(alist, K)
  print(resultlist[K-1])

main()

Submission status: Time Limit Exceeded

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

for i in range(n - 1):
    for j in range(i + 1, n):
        mul.append(list[i] * list[j])

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

Submission status: Time Limit Exceeded

Solution code:
import sys
INF = 10**18+5
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(a)
    plus = 0
    minus = 0
    zero = 0
    for i in range(n):
        if a[i] > 0:
            plus += 1
        elif a[i] < 0:
            minus += 1
        else:
            zero += 1

    mc = minus*plus
    zc = (zero*(zero-1)/2) + (zero * (plus+minus))
    pc = (plus*(plus-1)/2) + (minus*(minus-1)/2)
    if mc >= k:
        l = -INF
        r = 0
        while(l+1 < r):
            x = (l+r)//2
            total = 0
            for i in range(n):
                if a[i] < 0:
                    l2 = minus+zero-1
                    r2 = n
                    while(l2+1 < r2):
                        x2 = (l2+r2)//2
                        if a[x2]*a[i] >= x:
                            l2 = x2
                        else:
                            r2 = x2
                    total += n-r2
                else:
                    l2 = -1
                    r2 = minus
                    while(l2+1 < r2):
                        x2 = (l2+r2)//2
                        if a[x2]*a[i] < x:
                            l2 = x2
                        else:
                            r2 = x2
                    total += r2
                if a[i]*a[i] < x:
                    total -= 1
            total //= 2
            if total < k:
                l = x
            else:
                r = x
        ans = l
    elif mc + zc >= k:
        ans = 0
    else:
        l = 0
        r = INF
        while(l+1 < r):
            x = (l+r)//2
            total = 0
            for i in range(n):
                if a[i] < 0:
                    l2 = -1
                    r2 = minus
                    while(l2+1 < r2):
                        x2 = (l2+r2)//2
                        if a[x2]*a[i] >= x:
                            l2 = x2
                        else:
                            r2 = x2
                    total += n-r2
                else:
                    l2 = minus+zero-1
                    r2 = n
                    while(l2+1 < r2):
                        x2 = (l2+r2)//2
                        if a[x2]*a[i] < x:
                            l2 = x2
                        else:
                            r2 = x2
                    total += r2
                if a[i]*a[i] < x:
                    total -= 1
            total //= 2
            if total < k:
                l = x
            else:
                r = x
        ans = l

    print(ans)


main()

Submission status: Time Limit Exceeded

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


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


ans = []
for x in range(len(A)):
    for y in range(x+1, len(A)):
        ans.append(A[x]*A[y])
ans.sort()
print(ans[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

ways = list(itertools.combinations(A, 2))
res = []

for each in ways:
    res.append(each[0] * each[1])

res = sorted(res)

print(res[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

INF = 10**18+5


def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    a = sorted(a)
    l = -INF
    r = INF

    while(l+1 < r):
        x = (l+r)//2
        total = 0
        for i in range(n):
            if a[i] < 0:
                l2 = -1
                r2 = n
                while(l2+1 < r2):
                    x2 = (l2+r2)//2
                    if a[x2]*a[i] >= x:
                        l2 = x2
                    else:
                        r2 = x2
                total += n-r2
            else:
                l2 = -1
                r2 = n
                while(l2+1 < r2):
                    x2 = (l2+r2)//2
                    if a[x2]*a[i] < x:
                        l2 = x2
                    else:
                        r2 = x2
                total += r2
            if a[i]*a[i] < x:
                total -= 1
        total //= 2
        if total < k:
            l = x
        else:
            r = x

    print(l)


main()

Submission status: Time Limit Exceeded

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

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

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    for a in A:
      if a >= 0:
        ll = -1
        rr = N
        while(ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            ll = cc
          else:
            rr = cc
        x += ll+1
      else:
        ll = -1
        rr = N
        while (ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            rr = cc
          else:
            ll = cc
        x += N-rr
      if a*a < c:
        x -=1
    x //= 2
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

  INF = 10**18+1
  l = -INF
  r = INF
  while(l+1 < r):
    # 積がc未満となるペアの個数xを求める。
    # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
    c = (l+r)//2
    x = 0
    for a in A:
      if a >= 0:
        ll = -1
        rr = N
        while(ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            ll = cc
          else:
            rr = cc
        x += ll+1
      else:
        ll = -1
        rr = N
        while (ll+1 < rr):
          cc = (ll+rr)//2
          if a*A[cc] < c:
            rr = cc
          else:
            ll = cc
        x += N-rr
      if a*a < c:
        x -=1
    x //= 2
    if x < K:
      l = c
    else:
      r = c
  print(l)

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

INF = 10**18+1
l = -INF
r = INF
while(l+1 < r):
  # 積がc未満となるペアの個数xを求める。
  # K番目の積は、それより小さい積の個数がK未満である席のうち最大のもの。
  c = (l+r)//2
  x = 0
  for a in A:
    if a >= 0:
      ll = -1
      rr = N
      while(ll+1 < rr):
        cc = (ll+rr)//2
        if a*A[cc] < c:
          ll = cc
        else:
          rr = cc
      x += ll+1
    else:
      ll = -1
      rr = N
      while (ll+1 < rr):
        cc = (ll+rr)//2
        if a*A[cc] < c:
          rr = cc
        else:
          ll = cc
      x += N-rr
    if a*a < c:
      x -=1
  x //= 2
  if x < K:
    l = c
  else:
    r = c
print(l)

Submission status: Time Limit Exceeded

Solution code:
N, K = input().split(' ')
nums = input().split(' ')

products = []
for i in range(len(nums)-1):
  for j in range(i+1,len(nums)):
    	products.append(int(nums[i])*int(nums[j]))
    
ranking = sorted(products)

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

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

li = []
new_int_list = list(itertools.combinations(int_list,2))
lenght = len(new_int_list)
for i in range(lenght):
    g = new_int_list[i]
    seki = g[0]*g[1]
    li.append(seki)
h = sorted(li)
print(h[k-1])

Submission status: Time Limit Exceeded

Solution code:
N, K= map(int, input().split())
A = list(map(int, input().split()))
posi = []
zero = []
nega = []
for i in A:
    if i == 0:
        zero.append(i) 
    elif i == abs(i):
        posi.append(i)
    else:
        nega.append(i)

sign = len(nega), len(zero), len(posi) # 掛けて負，0，正になるもの
sign_pair = [0]*3
sign_pair[0] = sign[0]*sign[2]
sign_pair[1] = (sign[0]+sign[2])*sign[1] + (sign[1]*(sign[1]-1))//2
# sign_pair[2] = (sign[0]*(sign[0]-1))//2 + (sign[2]*(sign[2]-1))//2

#print(sign_pair)

seki = []
if K <= sign_pair[0]:
    for i in nega:
        for j in posi:
            seki.append(i*j)
    seki.sort()
    print(seki[K-1])

elif sign_pair[0]+sign_pair[1] < K:
    for i in range(sign[0]):
        for j in range(i+1, sign[0]):
            seki.append(nega[i]*nega[j])
    for i in range(sign[2]):
        for j in range(i+1, sign[2]):
            seki.append(posi[i]*posi[j])
    seki.sort()
    print(seki[K-sign_pair[0]-sign_pair[1]-1])

else:
    print("0")

Submission status: Time Limit Exceeded

Solution code:
inp=[int(x) for x in input().split()]
n=inp[0]
k=inp[1]
l=[int(x) for x in input().split()]
mul=list()
for i in range(0,len(l)-1):
  for j in range(i+1,len(l)):
    mul.append(l[i]*l[j])

mul=list(mul)
mul.sort()
print(mul[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()))

wk = kai = 0
c = []
#c = [b[i][1]*b[j][1] for i in range(n-1) for j in range(i+1,n)]
b = list(combinations(a, 2))
c =[b[i][0]*b[i][1] for i in range(len(b))]
c.sort()        

print(c[k-1])

Submission status: Time Limit Exceeded

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

b = [[abs(i),i] for i in a]
b.sort()
wk = kai =0
c = [b[i][1]*b[j][1] for i in range(n-1) for j in range(i+1,n)]

c.sort()        

print(c[k-1])

Submission status: Time Limit Exceeded

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

b = [[abs(i),i] for i in a]
b.sort()
wk = kai =0
for i in range(n-1):
    for j in range(i+1,n):
        c.append(b[i][1]*b[j][1])
c.sort()        
print(c[k-1])