Problem:


Score: 400 points

Problem Statement

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

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

Constraints

All values in input are integers.

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

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

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

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

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

Sample Input 2

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

Sample Output 2

6

Sample Input 3

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

Sample Output 3

448283280358331064



Sample input:
4 3
3 3 -4 -2


Sample output:
-6

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

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

p = [k * v  for k, v  in itertools.combinations(aa, 2)]

p.sort()
print(int(p[K-1]))

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from numpy import prod

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

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

count = 1
li = []

for index, a in enumerate(A):
  for b in range(count, len(A)):
    li.append(a * A[b])

  count += 1

li.sort()

print(li[K-1])

Submission status: Time Limit Exceeded

Solution code:
def calc(nums, k):
    res = []
    for i in range(len(nums)):
        for j in range(i + 1,len(nums)):
            res.append(nums[i] * nums[j])
    res.sort()
    return res[k - 1]

if __name__ == '__main__':
    n, k = map(int, input().split())
    nums = list(map(int, input().split()))
    print(calc(nums, k))

Submission status: Time Limit Exceeded

Solution code:
import heapq

l = []

n,k = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
for i in range(n-1):
    for j in range(i+1,n):
        heapq.heappush(l,a[i]*a[j])

for i in range(k-1):
    heapq.heappop(l)
    
print(heapq.heappop(l))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a_list = list(map(int, input().split()))
a_list.sort()
plus_num = [i for i in a_list if i >= 0]
minus_num = [i for i in a_list if i < 0]
plus_length = len(plus_num) 
minus_length = len(minus_num) 

plus_length_all = int(plus_length * (plus_length - 1) + minus_length * (minus_length - 1)) / 2
minus_length_all = int(plus_length * minus_length)

if k >= minus_length_all:
    k -= minus_length_all
    all_num = []
    for i in range(len(plus_num)-1):
        for j in range(i+1, len(plus_num)):
            all_num.append(plus_num[i] * plus_num[j])
    for i in range(len(minus_num)-1):
        for j in range(i+1, len(minus_num)):
            all_num.append(minus_num[i] * minus_num[j])    
    print(sorted(all_num)[k-1])
else:
    all_num = []
    for plus in plus_num:
        for minus in minus_num:
            all_num.append(plus * minus)
    print(sorted(all_num)[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

import itertools

comb_list = list(itertools.combinations(a_list, 2))

product_list = []
for i in range(len(comb_list)):
    product_list.append(comb_list[i][0]*comb_list[i][1])

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

C = combinations(sorted(A), 2)

print(sorted([x[0] * x[1] for x in C])[K - 1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

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

arr = list(combinations(arr, 2))

for index, i in enumerate(arr):
    tem = i[0] * i[1]
    arr[index] = tem


arr.sort()

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

Submission status: Time Limit Exceeded

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

for i in range(n):
    for j in range(n):
        if i < j:
            r.append(a[i]*a[j])

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

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
pairs = int(n*(n-1)/2)
a = list(map(int,input().split()))
b = []
for i in range(n):
    for j in range(n):
        if i < j:
            b.append(a[i]*a[j])
c = sorted(b)
print(c[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
array = list(map(int, input().split()))
minus = []
zero = []
plus = []        
for i in range(N):
  temp = array[i]
  if temp == 0:
    zero.append(temp)
  elif temp < 0:
    minus.append(temp)
  else:
    plus.append(temp)
Z = len(zero)
M = len(minus)
P = len(plus)
ans = []
if K <= M*P:
  for i in range (M):
    for j in range(P):
      ans.append(minus[i]*plus[j])
  Ans = sorted(ans)
  print(Ans[K-1])
elif K <= (M*P + Z*(Z-1)/2 + Z*(M+P)):
  print(0)
else:
  Ks = K - (M*P + Z*(Z-1)/2 + Z*(M+P))
  if M >= 2:
    for i in range (M):
      for j in range(i+1,M):
        ans.append(minus[i]*minus[j])
  if P >= 2:
    for i in range (P):
      for j in range(i+1,P):
        ans.append(plus[i]*plus[j])
  Ans = sorted(ans)
  print(Ans[int(Ks)-1])

Submission status: Time Limit Exceeded

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


def kake(X):
    return (X[0] * X[1])


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

l2 = []
for i in l:
    ax = kake(i)
    l2.append(ax)

l3 = sorted(l2)
print(l3[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))

X=0
ans=[]
for i in l:
    ans.append(i[0]*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()))
ans = []

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

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

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


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

import random
from itertools import combinations

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

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

    A.sort()

    lst = []

    
    combs = combinations(A, 2)
    for a, b in combs:
        lst.append(a*b)

    # print(lst)
    print(select(lst,K-1))
    pass

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

import itertools

def func(x):
  return x[0]*x[1]

c = list(itertools.combinations(A,2))
c = sorted(list(map(func,c)))
print(c[K-1])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3


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

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

    A.sort()

    lst = []

    
    combs = combinations(A, 2)
    for a, b in combs:
        lst.append(a*b)

    # print(lst)
    print(select(lst,K-1))
    pass

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
nk = list(map(int, input().split()))
n = nk[0]
k = nk[1]

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

a_posi = []
a_nega = []
a_zero = []

for aa in a:
    if aa > 0:
        a_posi.append(aa)
    elif aa == 0:
        a_zero.append(aa)
    else:
        a_nega.append(aa)

num_a_posi = len(a_posi)
num_a_nega = len(a_nega)
num_a_zero = len(a_zero)

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

num_posi_result = combination(num_a_posi) + combination(num_a_nega)
num_nega_result = num_a_posi * num_a_nega
num_zero_result = combination(n) - num_posi_result - num_nega_result

nega_posi = 0

if k <= num_nega_result:
    nega_posi = -1
else:
    k -= num_nega_result
    if k <= num_zero_result:
        nega_posi = 0
    else:
        k -= num_zero_result
        nega_posi = 1

target_list = []
if nega_posi == -1:
    for ap in a_posi:
        for an in a_nega:
            target_list.append(ap*an)
elif nega_posi == 0:
    target_list.append(0)
else:
    for i in range(len(a_posi)):
        for j in range(i+1, len(a_posi)):
            target_list.append(a_posi[i] * a_posi[j])
    
    for i in range(len(a_nega)):
        for j in range(i+1, len(a_nega)):
            target_list.append(a_nega[i] * a_nega[j])  
    

target_list.sort()

if nega_posi == 0:
    print(0)
else:
    print(target_list[int(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(n):
    x = a[i]
    for j in range(i+1,n):
        y = a[j]
        tmp = x*y
        num = 0
        for h in result:
            if tmp<h:
                break
            else:
                num+=1
        result.insert(num,tmp)

print(result[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

lst = [t[0] * t[1] for t in itertools.combinations(A, 2)]

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

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

p = list(map(lambda x: x[0] * x[1], combinations(A, 2)))
p.sort()

print(p[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)
            for i in a_neg:
                res -= bisect_left(a_pos,(x+i-1)//i)
            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
            for i,ai in enumerate(a_neg):
                v = bisect_right(a_neg,x//ai)
                if v > i+1: res += v-i-1
            for i,ai in enumerate(a_pos):
                v = bisect_right(a_pos,x//ai)
                if v > i+1: res += v-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:
import heapq

N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
heapq.heapify(B)

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

for i in range(K-1):
    heapq.heappop(B)

print(heapq.heappop(B))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools

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

p = [k * v  for k, v  in itertools.combinations(aa, 2)]
"""
for i in range(N-1):
  for j in range(i+1, N):
    p.append()
"""
"""
p = aa[:, np.newaxis] * aa[np.newaxis].astype(float)
f = np.tril(np.ones((N, N)))
# print(f)
p[f == 0] = np.nan
q = p.flatten()
"""
p.sort()
# print(q)
# print(p)
# p = list(set(p))
print(int(p[K-1]))

Submission status: Time Limit Exceeded

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

from itertools import combinations 

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
[n,k]=map(int,input().split())
a=np.array(list(map(int,input().split())))
b=a
for i in range(len(a)-1):
    if i==0:
        c=np.delete(a,0)*a[i]
    else:
        c=np.delete(a,range(0,i+1))*a[i]
    b=np.concatenate((b,c), axis=None)
b=sorted(list(np.delete(b,range(0,n))))
print(b[k-1])

Submission status: Time Limit Exceeded

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

l = []

for i in range(n):
  s = a[i]
  ls = a[i+1:n]
  lk = list(map(lambda x: x*s, ls))
  l += lk
l.sort()

print(l[k-1])

Submission status: Time Limit Exceeded

Solution code:
NK = input().split(" ")
As = input().split(" ")
As = [int(i) for i in As]
n = [i for i in range(len(As))]
times = [As[i]*As[x] for i in n for x in n if i > x]
times.sort()
print(times[int(NK[1])-1])

Submission status: Time Limit Exceeded

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

import sys
import math
import bisect


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

    result = []
    for i in range(n-1):
        for j in range(i+1, n):
            e = a[i] * a[j]
            index = bisect.bisect_left(result, e)
            result.insert(index, e)
            if debug:
                log("i=%d, j=%d, result=%s" % (i, j, result))

    return  result[k-1]


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

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

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


#comb = list(itertools.combinations_with_replacement(A, 2))
comb = list(itertools.combinations(A, 2))

times = sorted([item[0]*item[1] for item in comb])
#print(times)

print(times[K-1])

Submission status: Time Limit Exceeded

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

for item in A:
  if item<0:
    M.append(item)
  elif item==0:
    Z.append(item)
  else:
    P.append(item)

#print(M)
#print(Z)
#print(P)
    
#積の個数
minus = len(M)*len(P)
plus = len(M)*(len(M)-1)//2+len(P)*(len(P)-1)//2
zero = N*(N-1)//2-minus-plus
#print(minus,zero,plus)

if K<=minus:
  minus_list=[]
  for m in M:
    for p in P:
      minus_list.append(m*p)
  minus_list.sort()
  print(minus_list[K-1])
elif K>minus and K<= (minus+zero):
  print(0)
else:
  plus_list=[]
  for i in range(0,len(M)-1):
    for j in range(i+1,len(M)):
      plus_list.append(M[i]*M[j])
  for k in range(0,len(P)-1):
    for l in range(k+1,len(P)):
      plus_list.append(P[k]*P[l])
  plus_list.sort()
  #print(plus_list)
  print(plus_list[K-1-minus-zero])

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

Submission status: Time Limit Exceeded

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

main()

Submission status: Time Limit Exceeded

Solution code:
def main():
    import itertools
    import sys
    input = sys.stdin.readline

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

    nums = [i for i in range(N)]
    seki = sorted([A[i[0]] * A[i[1]] for i in itertools.combinations(nums, 2)])

    print(seki[K - 1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
[N,K] = [int(s) for s in input().rstrip().split(' ')]
A = [int(s) for s in input().rstrip().split(' ')]
L_a = [] #負
L_b = [] #0
L_c = [] #正
for x in A:
  if x > 0:
    L_a.append(x)
  elif x < 0:
    L_c.append(x)
  else:
    L_b.append(x)
a = len(L_a)
b = len(L_b)
c = len(L_c)
if a*c >= K:
  L = []
  for i in range(a):
    for j in range(c):
      L.append(L_a[i]*L_c[j])
  print(sorted(L)[K-1])
else:
  if a*c + b*(a+c) + b*(b-1)// 2 >= K:
    print(0)
  else:
    K_new = K - (a*c + b*(a+c) + b*(b-1) // 2)
    L = []
    if a != 0:
      for i in range(a):
        for j in range(i,a):
          if i != j:
            L.append(L_a[i]*L_a[j]) 
    if c != 0:
      for i in range(c):
        for j in range(i,c):
          if i != j:
            L.append(L_c[i]*L_c[j]) 
    print(sorted(L)[K_new-1])

Submission status: Time Limit Exceeded

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

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

newLst = sorted(newLst)
print(newLst[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
def main(n,k,a):
    lst = [i[0]*i[1] for i in itertools.combinations(a, 2)]
    lst.sort()
    return lst[k-1]

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

Submission status: Time Limit Exceeded

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

nC = list(itertools.combinations(A, 2))
C = []
for i in nC:
    C.append(i[0]*i[1])
C.sort()
print(C[K-1])

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

for i in range(n):
  x = q[i]
  for j in range(i+1, n):
    heapq.heappush(ans, x * q[j])
mins = heapq.nsmallest(k, ans)
print(mins[-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 = []
for v in itertools.combinations(L, 2):
    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:
from itertools import combinations 
from heapq import nsmallest 
n,k = map(int, input().split())
test_list = map(int, input().split())
res = nsmallest(k, combinations(test_list, 2), key = lambda sub: sub[0] * sub[1]) 

a,b = res[-1]
print(a*b)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

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

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

mulli=sorted(mulli)
print(mulli[k-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

main()

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
from functools import reduce
N , K = map(int, input().split())
A = [int(i) for i in input().split()]
ls =[]
comb = combinations(A, 2)
for i in list(comb):
    ls.append(reduce((lambda x,y: x*y),i))

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

Submission status: Time Limit Exceeded

Solution code:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
#print(N)
#case = (N(N-1))/2
com = []
cnt = 0
maxval = A[-1]
'''
if K >= case:
  for i in range(N):
    com.append
  com =

'''

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

com.sort()
#print(com)
print(com[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a = list(map(int, input().split()))
kumi = []
for p in range(len(a)):
    for q in range(len(a)):
        if p < q:
            kumi.append(a[p] * a[q])
kumi.sort()
print(kumi[k-1])

Submission status: Time Limit Exceeded

Solution code:

def insertion_sort(array):
    n = len(array)
    for i in range(1, n):
        tmp = array[i] # 挿入する値を退避
        if tmp < array[i-1]:
            # 挿入する位置までずらしていく
            j = i
            while True:
                array[j] = array[j-1]
                j -= 1
                if j == 0 or tmp >= array[j-1]:
                    break
            array[j] = tmp # 空いた位置に退避していた値を挿入

# デバッグ
if __name__ == "__main__":
    n, k =(int(x) for x in input().split())
    a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
    lis = []

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

    print(lis[k-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
N, K = input().split(" ")

nums = input().split(" ")
nums = [int(n) for n in nums]

products = []
for i in range(len(nums)):
    for j in range(i + 1, len(nums)):
        product = nums[i] * nums[j]
        if len(products) == 0:
            products.append(product)
        elif len(products) >= int(K):
            if products[-1] > product:
                insert_index = bisect.bisect_left(products, product)
                products.insert(insert_index, product)
            else:
                pass
        else:
            insert_index = bisect.bisect_left(products, product)
            products.insert(insert_index, product)

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

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import itertools
comb = list(itertools.combinations(A, 2))
prod = [a * b for a, b in comb]
prod = sorted(prod)
print(prod[K - 1])

Submission status: Time Limit Exceeded

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

l = []
i = 0
while i < N-1:
  j = i + 1
  while j < N:
    x = A[i]*A[j]
    iidx = bisect.bisect_left(l, x)
    l.insert(iidx, x)
    j += 1
  i += 1
print(l[K-1])