Problem:


Score: 400 points

Problem Statement

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

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

Constraints

All values in input are integers.

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

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

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

Input

Input is given from Standard Input in the following format:

N K
A_1 A_2 \dots A_N

Output

Print the answer.

Sample Input 1

4 3
3 3 -4 -2

Sample Output 1

-6

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

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

Sample Input 2

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

Sample Output 2

6

Sample Input 3

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

Sample Output 3

448283280358331064



Sample input:
4 3
3 3 -4 -2


Sample output:
-6

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations


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

    C = combinations(A, 2)

    B = []
    for v in C:
        B.append(v[0] * v[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()))
al=[]
for i in range(N):
    for j in range(i+1,N):
        al.append(A[i]*A[j])
al.sort()
print(al[K-1])

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int,input().split()))
ansList = []
#全ペアの積を求める
for i in range(N - 1):
    for j in range(i + 1, N):
        ansList.append(A[i] * A[j])

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

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

    seki = sorted([A[i[0]] * A[i[1]] for i in comb])

    print(seki[K - 1])


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import bisect
n, k = map(int, input().split())
minus = []
zero = 0
plus = []
lm = 0
lp = 0
for i in map(int, input().split()):
  if i < 0:
    minus.append(-i)
    lm += 1
  elif i == 0:
    zero += 1
  else:
    plus.append(i)
    lp += 1

minus.sort()
plus.sort()

def test(x):
  count = 0
  if x < 0:
    x = -x
    for i in minus:
      count += lp - bisect.bisect_left(plus, -(-x//i))
    return count >= k
  
  if x == 0:
    count = lm*lp
    return count + zero*(n-zero) + zero*(zero-1)//2 >= k
  
  count = lm*lp + zero*(n-zero) + zero*(zero-1)//2
  for i in range(lm-1):
    t = minus[i]
    count += bisect.bisect_right(minus[i+1:], x//t)
  for i in range(lp-1):
    t = plus[i]
    count += bisect.bisect_right(plus[i+1:], x//t)
  return count >= k

ng = -(10**18)
ok = 10**18
while ok-ng > 1:
  mid = (ok+ng)//2
  if test(mid):
    ok = mid
  else:
    ng = mid
print(ok)

Submission status: Time Limit Exceeded

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

products = (val*second_val for idx, val in enumerate(A) for second_val in A[idx+1:])
sorted_products = sorted(products)
print(sorted_products[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import heapq

N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
C = [c[0]*c[1] for c in combinations(A, 2)]
heapq.heapify(C)
print(heapq.nsmallest(K, C)[-1])

Submission status: Time Limit Exceeded

Solution code:
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)):
        products.append(nums[i] * nums[j])
# 3重for文にするとか
print(sorted(products)[int(K) - 1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

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

prods = []
cnt = 0
for n in range(N):
    for j in range(n+1, N):
        cnt += 1
        prods.append(int(A[n]) * int(A[j]))
        
prods.sort()
print(prods[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

sorted_A = sorted(A)
num_pair = N * (N-1) / 2

B = []
for perm in list(itertools.combinations(A, 2)):
    B.append(perm[0]*perm[1])

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

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

ans = sorted(ans)

print(ans[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

if __name__ == '__main__':
  main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

n, k = map(int, input().split())
a = [int(x) for x in input().split()]

combi = list(combinations(a, 2))

ans = []
for x, y in combi:
    ans.append(x * y)

print(sorted(ans)[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.permutations(A, 2)]

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

Submission status: Time Limit Exceeded

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

ans = list(itertools.combinations(a, 2))
ans = np.array(ans)

ans = np.prod(ans, axis = 1)
ans = np.sort(ans)

print(ans[k-1])

Submission status: Time Limit Exceeded

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

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

p.sort()
print(p[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 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())
alist = list(map(int,input().split()))
blist = []

for i in range(n):
    a = alist[i]
    m = i + 1
    for h in range(m, n):
        b = alist[h]
        blist.append(a*b)

blist.sort()

print(blist[k-1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

n,k=map(int, input().split())
a=list(map(int, input().split()))
lst = []
for i in itertools.combinations(a, 2):
    lst.append(i[0]*i[1])
lst.sort()
print(lst[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):
  for j in range(N - i - 1):
    B = B + [A[i] * A[i + j + 1]]
    
B.sort()
print(B[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

INPUT = LIST()
N = INPUT[0]
K = INPUT[1]

A = LIST()

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

for k in range(K-1):
    tmp_min = min(l)
    l.remove(tmp_min)
print(min(l))

Submission status: Time Limit Exceeded

Solution code:
import itertools

N, K= map(int,input().split())
num_list = list(map(int,input().split()))
ans_list = []
for i,j in itertools.combinations(num_list,2):
  ans_list.append(i*j)
ans_list = sorted(ans_list)
print(ans_list[K-1])

Submission status: Time Limit Exceeded

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

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

print(A[K-1])

Submission status: Time Limit Exceeded

Solution code:
from heapq import heappush, nsmallest
first_line = input().split()
n = int(first_line[0])
k = int(first_line[1])
numbers = input().split()
numbers = [int(n) for n in numbers]
result = []
for i in range(n):
    for j in range(i+1,n):
        heappush(result, numbers[i]*numbers[j])
print(nsmallest(k, result)[-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools


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

LL = list(itertools.combinations(L,2))
LLL = []

for nl in LL:
    LLL.append(nl[0]*nl[1])

LLL.sort()

print(LLL[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import bisect
n,k = [int(i) for i in input().split()]

l = [int(i) for i in input().split()]

ans = []
for x,y in itertools.combinations(l,2):
    bisect.insort(ans,x*y)

print(ans[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:


n, k = map(lambda x: int(x), input().split())
a_n = list(map(lambda x: int(x), input().split()))

mul_lst = []

for i in range(n):
    for j in range(n):
        if i != j:
            if i < j:
                mul_lst.append(a_n[i]*a_n[j])


mul_lst.sort()
#print(mul_lst)

print(mul_lst[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations as co

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

arr = [int(i) for i in input().split()]

combi = co(arr,2)

arr = []

for item in list(combi) :
  
  arr.append(item[0]*item[1])
  
arr.sort()

print(arr[k-1])

Submission status: Time Limit Exceeded

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

list=[]
for i in range(len(arr)-1):
    for j in range(i+1,len(arr)):
        val=int(int(arr[i])*int(arr[j]))
        list.append(val)

print(sorted(list)[int(k)-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
A = list(map(int , input().split()))
B = list(map(int , input().split()))
mm = list(itertools.combinations(B, 2))
list_2 = list(map(lambda x: x[0] * x[1], mm))
print(sorted(list_2)[A[1]-1])

Submission status: Time Limit Exceeded

Solution code:
b = input().split(" ")
n = int(b[0])
k = int(b[1])
a = input().split(" ")
for i in range(n):
	a[i] = int(a[i])
d = {}
for i in range(n-1):
	for j in range(i+1,n):
		s = a[i] * a[j]
		if s in d:
			d[s] += 1
		else:
			d[s] = 1
l = list(d.items())
l = sorted(l, key=lambda x:x[0])
m = 0
i = 0
while m < k:
	m += l[i][1]
	if m >= k:
		print(l[i][0])
	else:
		i += 1

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = sorted([int(i) for i in input().split()])
from itertools import combinations
test = []
for a in combinations(A,2):
    test.append(a[0] * a[1])
print(sorted(test)[K-1])

Submission status: Time Limit Exceeded

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

ret = []

for n in range(N):
  for nn in range(n+1, N):
    ret.append(A[n]*A[nn])

ret = sorted(ret)
print(ret[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = [int(i) for i in input().split()]
numbers = [int(i) for i in input().split()]
calc_list = [pair[0] * pair[1] for pair in list(itertools.combinations(numbers,2))]
print(sorted(calc_list)[K - 1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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


if __name__=='__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a = input().split()
b = input().split()

numArr = int(a[0])
pos    = int(a[1])
arr = [int(b[i]) for i in range(numArr)]

prods = []

for i in range(numArr):
  for j in range(i+1,numArr):
    prods.append(arr[i]*arr[j])
    
prods.sort()
print(prods[pos-1])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)


#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
愚直に操作を実装する

#solution:
N=int(input())
S=[input() for i in range(N)]
import collections as cl
#print(S)
a=cl.Counter(S)
b=(a.most_common())
#print(b)
maxvalue=b[0][1]
ans=[]
for i in range(len(b)):
    if b[i][1] == maxvalue:
        ans.append(b[i][0])
for w in sorted(ans):
    print(w)
"""
N,K=pin()#KはAのうち2つを選んだとき積K番目の値 重複する値を含めるよ！
A=list(pin())
Aplus,Aminus=[],[]
zpm=[0]*3#0と負と正の数　これで数を減らして全探索ちゃうか
for num in A:
    if num==0:
        zpm[0]+=1
    elif num>0:
        zpm[1]+=1
        Aplus.append(num)
    else:
        zpm[-1]+=1
        Aminus.append(num)
#print(zpm)
zeros=zpm[0]*(N-zpm[0])+zpm[0]*(zpm[0]-1)//2 #0となにかの積
plus=(zpm[1]*(zpm[1]-1)+zpm[-1]*(zpm[-1]-1))//2#符号が同じものの積
minus=zpm[1]*zpm[-1]#違うものの積
"""
pz=[zeros,plus,minus]
print(pz)
print((N*(N-1)//2)-sum(pz)) #0:網羅性があるよ
"""
if K<=minus:#求める解は負=>AplusのなにかとAminusのなにかの積
    ans=[]
    for ap in Aplus:
        for am in Aminus:
            ans.append(ap*am)
    ans.sort()
    print(ans[K-1])
    
elif K<=minus+zeros:# 求める解は直ちに0になる
    print(0)
else:#求める解は正！
    ans=[]
    aps=len(Aplus)
    ams=len(Aminus)
    for i in range(aps):
        for j in range(i+1,aps):
            ans.append(Aplus[i]*Aplus[j])
    for m in range(ams):
        for k in range(m+1,ams):
            ans.append(Aminus[m]*Aminus[k])
    ans.sort()
    print(ans[K-(minus+zeros)-1])
#zpm_product=[,,]#今度は積がどうなるかやろう 
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])

Submission status: Time Limit Exceeded

Solution code:
inp = input().split()
winInd = int(inp[1]) - 1
nums = list( map(int,input().split()) )

N = int(inp[0])
numWays = (N*(N-1))/2

pairs = []

for i, n in enumerate(nums):
    for nn in nums[i + 1:]:
        pairs.append(n*nn)
        if(len(pairs) == numWays):
            break
    if(len(pairs) == numWays):
            break
pairs.sort()

print(pairs[winInd])

Submission status: Time Limit Exceeded

Solution code:
def solve():
    N, M = map(int, input().split())
    A = list(map(int, input().split()))

    l = []
    for i in range(N):
        for j in range(i+1, N):
            l.append(A[i] * A[j])
    l.sort()
    return l[M-1]

print(solve())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

l=[]

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

print(new[k-1])

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

a_list = list(map(int, input().split()))
a_list.sort()

multiples = []

for i in range(n):
    for j in range(n):
        if i >= j:
            continue
        else:
            heapq.heappush(multiples, a_list[i]*a_list[j])
    
ans = 0        
for i in range(k):
    ans = heapq.heappop(multiples)
    
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, k = [int(x) for x in input().split()]
items = [int(x) for x in input().split()]
 
score = [[items[i]*items[j] for j in range(i+1, n)] for i in range(n)]
scores = sum(score, [])
srt = sorted(scores)
print(srt[k - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

comb = itertools.combinations(a, 2)
print(sorted(x[0] * x[1] for x in comb)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

p = itertools.combinations(a_list, 2)
ans_list = []

for i,j in p:
    ans_list.append(i*j)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n,k=map(int,input().split())
arr=list(map(int,input().split()))
lst=[]
for i in range(len(arr)):
    for j in range(i+1,len(arr)):
        lst.append(arr[i]*arr[j])
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()))
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 itertools

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

result = map(lambda x: x[0] * x[1], itertools.combinations(AS, 2))
result = sorted(result)

print(result[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

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

nums.sort()

print(nums[K-1])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
from itertools import combinations

def input():
    return sys.stdin.readline()[:-1]


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

AA = sorted((i*j for i, j in combinations(A, 2)))
print(AA[K-1])

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int, input().split())
A = list(map(int, input().split()))
l = list()
for _ in range(len(A)):
    k = _ + 1
    while k != len(A):
        l.append(A[_]*A[k])
        k+=1
print(sorted(l)[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
N, K = map(int, input().split())
Al = list(map(int, input().split()))
#print(Al)
a = [a*b for a, b in list(combinations(Al,2))]
a.sort()
print(a[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
line = input().split(" ")
N, K = [int(i) for i in line]
line = input().split(" ")
A = [int(a) for a in line]

pairs = combinations(A, 2)

ans = sorted(pairs, key=lambda x: x[0] * x[1])[K - 1]
print(ans[0] * ans[1])

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
mylist = []
for i in range(0,N-1):
    for j in range(i+1,N):
        mylist += [A[i]*A[j]]
mylist.sort()
print(mylist[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
        if result==[]:
            result.append(tmp)
        else:
            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:
n, k = map(int,input().split())
a = list(map(int,input().split()))

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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

r = []
for i in range(len(A)-1):
  for j in range(i+1,len(A)):    
    #if i==j:
    #  continue
    r.append( A[i]*A[j] )

#print(K,len(A), len(r) )

#print( sorted(r) )
print( sorted(r)[K-1] )

Submission status: Time Limit Exceeded

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

#cnt=(n*(n-1))//2
#s=sorted(a)
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:
import itertools

cnt, ind = map(int, input().split())
values = list(map(int, input().split()))

lst = list(itertools.combinations(values, 2))
l = [i[0] * i[1] for i in lst]
l.sort()
print(l[ind-1])

Submission status: Time Limit Exceeded

Solution code:
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)]
comb = [i for i in itertools.combinations(nums, 2)]

seki = sorted([A[i[0]] * A[i[1]] for i in comb])

print(seki[K - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

n, k = list(map(int, input().split()))
a_list = list(map(int, input().split()))
a_list.sort()
comb = list(itertools.combinations(a_list, 2))

ans = []
for c in comb:
    ans.append(c[0]*c[1])
ans.sort()
print(ans[k-1])

Submission status: Time Limit Exceeded

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

p = [aa[i] * aa[j]  for i in range(N-1) for j in range(i+1, N)]
"""
for i in range(N-1):
  for j in range(i+1, N):
    p.append()
"""

p.sort()
# print(p)
# p = list(set(p))
print(p[K-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations

N, K = [int(n) for n in input().split()]
A = [int(n) for n in input().split()]
print(sorted([c[0]*c[1] for c in combinations(A, 2)])[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
lis = list(map(int, input().split()))
import itertools
com = list(itertools.combinations(lis, 2))
newlis = []
for i in range(len(com)):
    newlis.append(com[i][0] * com[i][1])
newlis.sort()
print(newlis[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):
    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:
def pairs(n , k , a):

    kakelist = []
    for i in range(n - 1):
        for w in range(1 + i , n):
            kakelist.append(a[i] * a[w])

    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(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.sort()
mib = -10 ** 18 * 2
mab = 10**18*2
c = 0
while mib != mab:
    b = (mib+mab)//2
    co = 0
    for i in a:
        mi = 0
        ma = n - 1
        if i >= 0:
            if i * a[0] > b:
                continue
            while mi != ma:
                mm = (mi + ma) // 2 + 1
                if i * a[mm] <= b:
                    mi = mm
                else:
                    ma = mm - 1
            co += mi+1
            if i * i <= b:
                co -= 1
        else:
            if i * a[-1] > b:
                continue
            while mi != ma:
                mm = (mi + ma) // 2
                if i * a[mm] <= b:
                    ma = mm
                else:
                    mi = mm + 1
            co += n - mi
            if i * i <= b:
                co -= 1
    if co//2 >= k:
        mab = b
    else:
        mib = b + 1
print(mib)

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

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

seki = []


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

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

seki = sorted(seki)
cnt = 0
for i in seki:
    cnt+=1
    if cnt == k:
        print(i)
        break

Submission status: Time Limit Exceeded

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

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

B.sort()

# output
print(B[K-1])

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
arr = input().split()
arr = [int(x) for x in arr]
num_pair = int((n*(n-1))/2)
answer = []
for i in range(0, n):
    for j in range(i+1, n):
        answer.append(arr[i] * arr[j])
answer.sort()
print(answer[k-1])

Submission status: Time Limit Exceeded

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

import heapq
h = []
for i in range(N-1):
  for j in range(i + 1, N):
    heapq.heappush(h, A[i] * A[j])
#print(h)

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

ans = []
for i in range(n):
    for j in range(1,n-i):
        m = a[i]*a[i+j]
        bisect.insort_left(ans, m)

print(ans[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 = []

for i in itertools.combinations(a, 2):
    pair_list.append(i[0] * i[1])

print(sorted(pair_list)[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:
import itertools
n,k=map(int, input().split())
a=list(map(int, input().split()))
l=[]
for x in itertools.combinations(a,2):
    l.append(x[0]*x[1])
l_sorted=sorted(l)
print(l_sorted[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import chain
n, k = map(int, input().split())
a = list(map(int, input().split()))
products = list(chain(*[[a[i] * a[j] for j in range(n) if i < j] for i in range(n)]))
products.sort()
print(products[k-1])

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from bisect import bisect_left, bisect_right

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

    As.sort()
    negAs = [-A for A in As[::-1]]
    A2s = [A*A for A in As]
    A2s.sort()

    def isOK(x):
        num = 0
        for A in As:
            if A > 0:
                i = bisect_right(As, x//A)
                num += i
            elif A == 0:
                if x >= 0:
                    num += N
            else:
                i = bisect_right(negAs, x//(-A))
                num += i
        i = bisect_right(A2s, x)
        num -= i
        num //= 2
        return num >= K

    ng, ok = -(10**18)-1, 10**18+1
    while abs(ok-ng) > 1:
        mid = (ng+ok) // 2
        if isOK(mid):
            ok = mid
        else:
            ng = mid

    print(ok)


solve()