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:
#coding utf-8
import collections

def main():
    question_d()

def question_d():
    nk = list(map(int,input().split()))
    inter = list(map(int,input().split()))

    n = int(nk[0]*(nk[0]-1)/2)
    ans = []
    j = 1

    for i in range(len(inter)):
        while j < len(inter):
            ans.append(inter[i]*inter[j])
            j+=1
        j = i+2

    print(sorted(ans)[nk[1]-1])
main()

Submission status: Time Limit Exceeded

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

border = 0
A.sort()
alist = []
for i in range(N):
    for j in range(i+1, N):
        val = A[i]*A[j]
        if len(A) > K and val > border and A[j] > 0: break
        alist.append(val)
        border = max(val, border)

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
import itertools
B = [x for x in itertools.combinations(A, 2)]
C = [B[x][0]*B[x][1] for x in range(len(B))]
D = sorted(C)
print(D[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
N,K = map(int, input().split())
A = list(map(int,input().split()))
cur = list()
for v in list(itertools.combinations(A, 2)):
    cur.append(v[0] * v[1])

list.sort(cur,reverse=False)
print(cur[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
n, k = map(int, input().split())
A = list(map(int, input().split()))
B = []
t = 0
for s, e in itertools.combinations(A, 2):
    B.append(s*e)
print(sorted(B)[k-1])

Submission status: Time Limit Exceeded

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

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

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

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

Submission status: Time Limit Exceeded

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


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

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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


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

result = []

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

result.sort()

print(result[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

ans_list = []

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

ans_list.sort()

print(ans_list[k - 1])

Submission status: Time Limit Exceeded

Solution code:
import itertools
def resolve_d():
    n, k = map(int, input().split())
    l = map(int, input().split())
    c = itertools.combinations(l, 2)
    results = []
    for combi in c:
        results.append(combi[0] * combi[1])
    results = sorted(results)
    print(results[k-1])
resolve_d()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import heapq

N,K=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
plus=[]
minus=[]
zeros=0
for a in A:
    if a>0:
        plus.append(a)
    elif a==0:
        zeros+=1
    else:
        minus.append(a)

q=[]
heapq.heapify(q)

if len(minus)*len(plus)>=K:
    for m in minus:
        for p in plus:
            heapq.heappush(q,m*p)
    for i in range(K):
        a=heapq.heappop(q)
    print(a)
else:
    K-=len(minus)*len(plus)
    zeros=zeros*(len(minus)+len(plus))+zeros*(zeros-1)//2
    if K<=zeros:
        print(0)
    else:
        K-=zeros
        for i in itertools.combinations(minus,2):
            heapq.heappush(q,i[0]*i[1])
        for i in itertools.combinations(plus,2):
            heapq.heappush(q,i[0]*i[1])
        for i in range(K):
            a=heapq.heappop(q)

        print(a)

Submission status: Time Limit Exceeded

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

ans = []
for i, v in enumerate(A[:-1]):
    for j in A[i+1:]:
        ans.append(v * j)

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

Submission status: Time Limit Exceeded

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

from itertools import permutations, combinations,combinations_with_replacement,product

def main():
#print(list(permutations(A)))
    comb=list(combinations(A,2))
#print(comb)

#mul=[]
#for i in comb:
#  mul.append(i[0]*i[1])

    mul = [i[0]*i[1] for i in comb]
  
#print(mul)
    sol = sorted(mul)
#print(sol)
    print(sol[K-1])

  
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a,b=[int(x) for x in input().split()]
li = list(map(int,input().split()))
rs=[]
i=0
while(i<len(li)):
    j=i+1
    while(j<len(li)):
        rs.append(li[i]*li[j])
        j=j+1
    i=i+1
print(sorted(rs)[b-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect
from copy import deepcopy

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

negs=[]
poss=[]
zers=[]
for i in range(n):
    if A[i]<0:
        negs.append(A[i])
    elif A[i]>0:
        poss.append(A[i])
    else: zers.append(A[i])

pairedpos=len(negs)*(len(negs)-1)/2+len(poss)*(len(poss)-1)/2
pairedneg=len(negs)*len(poss)
pairedzero=(len(negs)+len(poss))*len(zers)+len(zers)*(len(zers)-1)/2

ans=0
flg=0
if k<=pairedneg:
    flg=1
elif pairedneg<k<=pairedneg+pairedzero:
    ans=0
else: flg=2 

if flg==1:
    higher=0
    lower=-(1e+9)**2+1
    while abs(higher-lower)>1:
        cnt=0
        mid=int((higher+lower)//2)
        for i in range(len(poss)):
            idx=bisect.bisect_left(negs, -(-mid//poss[i]))
            cnt+=idx
        if cnt<=k-1:
            lower=mid
        else:
            higher=mid
    ans=lower

elif flg==2:
    lower=0
    higher=(1e+9)**2+1
    newnegs=[-negs[i] for i in range(len(negs))]
    newnegs=sorted(newnegs)
    while abs(higher-lower)>1:
        cnt=0
        mid=int((higher+lower)//2)
        for i in range(len(newnegs)):
            idx1=bisect.bisect_left(newnegs[i+1:], -(-mid//newnegs[i]))
            cnt+=idx1
        for j in range(len(poss)):
            idx2=bisect.bisect_left(poss[j+1:], -(-mid//poss[j]))
            cnt+=idx2
        if cnt<=(k-pairedneg-pairedzero)-1:
            lower=mid
        else:
            higher=mid
    ans=lower
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
L = list(map(int, input().split()))
S = []
for i, x in enumerate(L):
  for y in L[i+1:]:
    S.append(x*y)
print(sorted(S)[K-1])

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

lis2 = list(itertools.combinations(lis, 2))
lis3 = []
for i in lis2:
    lis3.append(i[0] * i[1])

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

Submission status: Time Limit Exceeded

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

ans = []

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

ans.sort(reverse = False)
print(ans[k-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n, k = map(int, input().split())
a_i = list(map(int, input().split()))
a_i.sort()
minus =  [-i for i in a_i if i < 0]
zero =  [i for i in a_i if i == 0]
plus =  [i for i in a_i if i > 0]
minuscount = len(minus)
zerocount = len(zero)
pluscount = len(plus)

#違符号
if k <= minuscount * pluscount:
    anslist = []
    for x in minus:
        for y in plus:
            anslist.append(-x * y)
    anslist.sort()
    print(anslist[k - 1])
#ゼロ
elif k <= minuscount * pluscount + zerocount * (minuscount + pluscount) + (zerocount * (zerocount - 1) / 2):
    print(0)
#同符号
else:
    temp = k - (minuscount * pluscount + zerocount * (minuscount + pluscount) + (zerocount * (zerocount - 1) / 2))
    anslist = []
    cnt1 = 0
    for x in minus:
        cnt1 += 1
        cnt2 = 0
        for y in minus:
            cnt2 += 1
            if cnt1 >= cnt2: continue
            anslist.append(x * y)
    cnt1 = 0
    for x in plus:
        cnt1 += 1
        cnt2 = 0
        for y in plus:
            cnt2 += 1
            if cnt1 >= cnt2: continue
            anslist.append(x * y)
    anslist.sort()
    print(anslist[int(temp) - 1])

Submission status: Time Limit Exceeded

Solution code:
def upper(N, A, y, x):
    # count: A[i] * y <= x
    if not A[-1] * y <= x:
        return 0
    lo = -1
    hi = N - 1
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if A[mid] * y <= x:
            hi = mid
        else:
            lo = mid
    return N - hi

def lower(N, A, y, x):
    # count: A[i] * y <= x
    if not A[0] * y <= x:
        return 0
    lo = 0
    hi = N
    while hi - lo > 1:
        mid = (lo + hi) // 2
        if A[mid] * y <= x:
            lo = mid
        else:
            hi = mid
    return lo + 1

def check(N, A, x):
    # count: p*q <= x
    C = 0
    for i in range(N):
        if A[i] == 0:
            if x >= 0:
                add = N - 1
            else:
                add = 0
        elif A[i] < 0:
            add = upper(N, A, A[i], x)
            if A[i] * A[i] <= x:
                add -= 1
        else:
            add = lower(N, A, A[i], x)
            if A[i] * A[i] <= x:
                add -= 1
        C += add
    return C // 2

def solve(N, K, A):
    lo = int(-1e20)
    hi = int(1e20)
    while hi - lo > 1:
        mid = (lo + hi) // 2
        # print('mid =', mid)
        C = check(N, A, mid)
        # print('C =', C)
        if C >= K:
            hi = mid
        else:
            lo = mid
    return hi

def solve_naive(N, K, A):
    L = []
    for i, x in enumerate(A):
        for y in A[:i]:
            L.append(x*y)
    L.sort()
    return L[K - 1]

def testing():
    A = list(map(int, input().split()))
    A.sort()
    N = len(A)
    for i in range(N*(N-1)//2):
        K = i + 1
        if solve(N, K, A) != solve_naive(N, K, A):
            print(N, K, A)
            break

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

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import bisect as bs
from decimal import Decimal
N, K = map(int,input().split())
a = sorted(list(map(int,input().split())))
INF = 10**18
l = -INF
r = INF
while (r - l > 1):
    mid = (l+r)//2
    cnt = 0
    for i in range(1,N):
        if a[i-1] < 0:
            cnt += N-i-bs.bisect_left(a[i:], Decimal(mid)/a[i-1])
        elif a[i-1] > 0:
            cnt += bs.bisect_right(a[i:], Decimal(mid)/a[i-1])
        else:
            if mid >= 0:
                cnt += N-i
    if cnt < K:
        l = mid
    else:
        r = mid
    
for p in range(l+1, r+1):
    cnt = 0
    for i in range(1,N):
        if a[i-1] < 0:
            cnt += N-i-bs.bisect_left(a[i:], Decimal(p)/a[i-1])
        elif a[i-1] > 0:
            cnt += bs.bisect_right(a[i:], Decimal(p)/a[i-1])
        else:
            if p >= 0:
                cnt += N-i
    if K <= cnt:
        print(p)
        exit(0)

Submission status: Time Limit Exceeded

Solution code:
import itertools

def pairs(k, arr):
    t_arr = list(itertools.combinations(arr, 2))
    a = sorted([t[0] * t[1] for t in t_arr])
    return a[k-1]

if __name__ == "__main__":
    n, k = map(int, input().split(' '))
    arr = [int(s) for s in list(input().split())]
    print(pairs(k, arr))

Submission status: Time Limit Exceeded

Solution code:
[n,k] = [int(x) for x in input().split()]
data = [int(x) for x in input().split()]
data.sort()
temp = []
for i in range(n-1):
    for j in range(i+1,n):
        temp.append(data[i]*data[j])

temp.sort()

print(temp[k-1])

Submission status: Time Limit Exceeded

Solution code:
from itertools import combinations
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def check(s,A):
    N,K = map(int, s.split())
    A = sorted([int(i) for i in A.split()])
    cnt_, cnt0 = 0, 0
    
    for a in A:
        if a > 0:
            break
        elif a == 0:
            cnt0 += 1
        else:
            cnt_ += 1
    sei = A[cnt0+cnt_:]
    hu = A[:cnt_]
    zero = A[cnt_:cnt_+cnt0]
    
    seihu_cnt = len(sei)*len(hu)
    zero_cnt = 0 if len(zero)==0 else len(zero)*(N-len(zero)) + combinations_count(len(zero),2)
    seki = []
    if K <= seihu_cnt:
        for i in hu:
            for j in sei:
                seki.append(i*j)
        if len(seki) > 1:
            seki.sort()
        print(seki[K-1])
    elif K <= seihu_cnt+zero_cnt:
        print(0)
    else:
        for a,b in combinations(sei, 2):
            seki.append(a*b)
        for a,b in combinations(hu, 2):
            seki.append(a*b)
        if len(seki) > 1:
            seki.sort()
        print(seki[K-1-seihu_cnt-zero_cnt])
    
s = input()
A = input()
check(s,A)

Submission status: Time Limit Exceeded

Solution code:
def solve():
    from sys import stdin
    f_i = stdin
    
    N, K = map(int, f_i.readline().split())
    A = map(int, f_i.readline().split())
    
    from itertools import combinations
    ans = sorted(x * y for x, y in combinations(A, 2))[K-1]
    
    print(ans)

solve()

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

for i in range(N-1):
    for j in range(i+1, N):
        p = A[i]*A[j]
        x = bisect.bisect_left(S,p)
        S.insert(x,p)

print(S[K-1])

Submission status: Time Limit Exceeded

Solution code:
import heapq

import numpy as np
from itertools import combinations

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

c_of_A = np.array(list(combinations(A, 2)))
p = np.prod(c_of_A, axis=1)
lip = p.tolist()
heapq.heapify(lip)
# print(lip, type(lip))

for i in range(K):
    ans = heapq.heappop(lip)
    # print(ans)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A.sort()
Nn = bisect.bisect_left(A, 0) # 負の数の数
Np = N - Nn
An = A[:Nn]
Ap = A[Nn:]
if Nn*Np >= K:  
  left = A[0]*A[-1] - 1
  right = max(A[0]**2, A[-1]**2) + 1
  while left+1 < right:
    mid = (left + right)//2
    c = 0
    res = False
    for an in An:
      idx = bisect.bisect_left(Ap, mid/an)
      c += Np - idx
      if c >= K:
        res = True
        break
    if res:
      right = mid
    else:
      left = mid
  
  ans = -10**20
  for an in An:
    idx = bisect.bisect_left(Ap, right/an)
    if idx < Np:
      ans = max(ans, Ap[idx]*an)
      if ans == right:
        break
else:
  k = K - Nn*Np
  An = [-an for an in An][::-1]
  left = -1
  right = 10**20
  while left+1 < right:
    mid = (left + right)//2
    c = 0
    for i, an in enumerate(An, 1):
      idx = bisect.bisect_right(An, mid/an)
      if idx > i:
        c += idx - i
    
    if c >= k:
      right = mid
    else:
      for i, ap in enumerate(Ap, 1):
        if ap:
          idx = bisect.bisect_right(Ap, mid/ap)
          if idx > i:
            c += idx - i
        else:
          c += Np - i
    
    if c >= k:
      right = mid
    else:
      left = mid
  
  ans = 10**20
  for an in An:
    idx = bisect.bisect_left(An, right/an)
    if idx < Nn:
      ans = min(ans, An[idx]*an)
      if ans == right:
        break
  for ap in Ap:
    if ap:
      idx = bisect.bisect_left(Ap, right/ap)
      if idx < Np:
        ans = min(ans, Ap[idx]*ap)
        if ans == right:
          break
    else:
      if right == 0:
        ans = 0
        break

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split(" "))
z = list(map(int,input().split(" ")))
ans = []
for x in range(0,n^1):
  for y in range(x+1,n):
  	ans.append(z[x]*z[y])
ans = sorted(ans)
print(ans[k-1])

Submission status: Time Limit Exceeded

Solution code:
n,k = map(int,input().split())
a = sorted(map(int,input().split()))
ans = []
for i in range(n - 1):
    for j in range(i + 1,n):
        ans.append(a[i] * a[j])
count = 1
sort_a = sorted(ans)
#for i in range(len(sort_a)-1):
#    if k == count:
 #       print(ans[i])
  #      break
   # elif sort_a[i] != sort_a[i + 1]:
    #    count += 1
print(sort_a[k-1])

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

def wantA(m):

    ret = 0

    for l in L:

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

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

        if ret >= K:
            return ret

    return ret

def wantB(m):

    ret = 0

    for i in range(len(R)):

        i = len(R) - 1 - i

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

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

        if ret >= K:
            return ret

    
    for i in range(len(L2)):

        i = len(L2)-1-i

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

        if ret >= K:
            return ret

    return ret
        

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

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

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

for i in range(N):

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

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

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

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

    while r - l != 1:

        m = (l+r) // 2

        num = wantA(m)

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

    print (r)

else:

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

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

    while r-l != 1:

        m = (l+r)//2

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


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

        #print (l,r)

    print (r)

Submission status: Time Limit Exceeded

Solution code:
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文にするとか


def merge(array):                                   # line1
    mid = len(array)                                # line2
    if mid > 1:
        half = int(mid / 2)                        # line3
        left = merge(array[:half])               # line4
        right = merge(array[half:])              # line5
        array = []                                  # line6
        while len(left) != 0 and len(right) != 0:   # line7
            if left[0] < right[0]:                  # line8
                array.append(left.pop(0))           # line9
            else:                                   # line10
                array.append(right.pop(0))          # line11
        if len(left) != 0:                          # line12
            array.extend(left)                      # line13
        elif len(right) != 0:                       # line14
            array.extend(right)                     # line15
    return array


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

Submission status: Time Limit Exceeded

Solution code:
import numpy

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

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

#S.sort()
T = numpy.sort(S)
print(T[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import itertools
N, K = map(int, input().split())
input_n = list(map(int, input().split()))
pair = itertools.combinations(input_n, 2)
# for i in pair:
#   print(i)
res = [i[0] * i[1] for i in pair]
res.sort()
if len(res) != 0:
    print(res[K-1])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import itertools
import sys
input = sys.stdin.readline

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

cm = list(itertools.combinations(a, 2))
alist = []
for nn in cm:
    tmp = nn[0] * nn[1]
    alist.append(tmp)
alist.sort()

print(alist[k-1])

Submission status: Time Limit Exceeded

Solution code:
a, *D, = [list(map(int, s.split())) for s in open(0)] 
D = D[0]
print((sorted([D[i] * D[j] for i in range(len(D)) for j in range(i + 1, len(D))])[a[1] - 1]))

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
ans = []
for i,num in enumerate(A):
    for j in range(i+1,N):
        ans.append(num * A[j])
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()))
del a[n:]
test = []


for i in range(1 << len(a)):
  output = []
  for j in range(len(a)):
    if ((i >> j) & 1) == 1:
      output.append(a[j])
    # print(output)
  if len(output) == 2:
    test.append(output[0] * output[1])

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

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10 ** 9) #再帰用
n, k = list(map(int,(input().split())))
a = list(map(int,(input().split())))

import itertools


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

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

Submission status: Time Limit Exceeded

Solution code:
input_line = input().split(" ")

N = int(input_line[0])
K = int(input_line[1])

An = input().split(" ")

#空のリストを用意
num_list = []

#順番に計算し、リストに結果を追加
for i in range(N-1):
	Ai = int(An[i])
	for j in range(i+1, N):
		Aj = int(An[j])
		num_list.append(Ai * Aj)

#ソート
num_list.sort()

print(num_list[K-1])

Submission status: Time Limit Exceeded

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

A.sort()

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import itertools

def main():

    # sys.stdin = open('input155d.txt')

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

    b = list(itertools.combinations(a,2))
    
    c = []
    for i in b:
        c.append(i[0] * i[1])


    sortb = sorted(c)
    print(sortb[k - 1])

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

for i in range(0,N):
    for j in range(i,N):
        if i!=j:
            H.append(A[i]*A[j])

H.sort()

print(H[K-1])

Submission status: Time Limit Exceeded

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

a.sort()

aa = []

counter = 0
for i in range(1, n):
  for j in range(i):
    aa.append(a[i] * a[j])
    if counter == k*2:
      break;

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

Submission status: Time Limit Exceeded

Solution code:
N, K = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
import itertools
for x in itertools.combinations(A, 2):
    B.append(x)
for x in range(len(B)):
    C.append(B[x][0]*B[x][1])
D = sorted(C)
print(D[K-1])

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import itertools
N,K=map(int,input().split())
S=np.array([ int(_) for _ in input().split()])
T=[]
for i in range(N-1):
  for j in range(i+1,N):
    T.append(S[i]*S[j])
T.sort()
print(T[K-1])

Submission status: Time Limit Exceeded

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

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

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

Submission status: Time Limit Exceeded

Solution code:
import itertools

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

N = INPT[0]
K = INPT[1]

ValueArr = list(map(int, input().split()))
hoge = itertools.combinations(ValueArr,2)

multiArr = []
for val in list(hoge):
    l = val[0]
    r = val[1]
    m = l * r
    multiArr.append(m)
print(sorted(multiArr)[K - 1])

Submission status: Time Limit Exceeded

Solution code:
input1 = list(map(int, (input().split())))
list_a = list(map(int, (input().split())))

N = input1[0]
K = input1[1]

m = -1000000000000000

list_a.sort()

counter = 0

# print(list_a)
b = []

for i in range(N):
    for j in range(i + 1, N):
        a = list_a[i] * list_a[j]
        b.append(a)

b.sort()

print(b[K-1])

Submission status: Time Limit Exceeded

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

neg = 0
negs = []
zero = 0
pos = 0
poss = []
for a in A:
  if a < 0:
    neg +=1
    negs.append(-a)
  elif a == 0:
    zero += 1
  else:
    pos += 1
    poss.append(a)
neg, zero, pos = neg * pos, zero *(neg + pos) + int((zero * (zero - 1)) / 2), int(((pos * (pos - 1)) + (neg * (neg - 1)))/ 2)

#print(neg, zero, pos)
#print(negs, poss)

import heapq
h = []
if K <= neg:
  #poss = sorted(poss, reverse=True)
  
  for n in negs:
    for p in poss:
      heapq.heappush(h, -n * p)
  for i in range(K - 1):
    heapq.heappop(h)
  print(heapq.heappop(h))
  pass
elif K <= neg + zero:
  print("0")
else:
  for i in range(max(len(negs) - 1, 0)):
    for j in range(i + 1, len(negs)):
      heapq.heappush(h, negs[i] * negs[j])
      
  for i in range(max(len(poss) - 1, 0)):
    for j in range(i + 1, len(poss)):
      heapq.heappush(h, poss[i] * poss[j])

  for i in range(K -neg - zero - 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()))
#A.sort()
ls = []
for i in range(N):
  for j in range(i):
    #if i!=j:
    ls.append(A[i]*A[j])
ls.sort()
print(ls[K-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 = np.arange(0)

for i in range(len(A)):
    if i == (len(A)-1):
        break
    else:
        B = np.append(B, A[i] * A[i+1:])

C = sorted(B)



print(C[K-1])

# B = A[0] * A[1:]
#
# print(B)

Submission status: Time Limit Exceeded

Solution code:
import bisect

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

A.sort()
Nn = bisect.bisect_left(A, 0) # 負の数の数
Np = N - Nn
An = A[:Nn]
Ap = A[Nn:]
if Nn*Np >= K:  
  left = A[0]*A[-1] - 1
  right = max(A[0]**2, A[-1]**2) + 1
  while left+1 < right:
    mid = (left + right)//2
    c = 0
    res = False
    for an in An:
      idx = bisect.bisect_left(Ap, mid/an)
      c += Np - idx
      if c >= K:
        res = True
        break
    if res:
      right = mid
    else:
      left = mid
  
  ans = -10**20
  for an in An:
    idx = bisect.bisect_left(Ap, right/an)
    if idx < Np:
      ans = max(ans, Ap[idx]*an)    
else:
  k = K - Nn*Np
  An = [-an for an in An][::-1]
  left = -1
  right = 10**20
  while left+1 < right:
    mid = (left + right)//2
    c = 0
    for i, an in enumerate(An, 1):
      idx = bisect.bisect_right(An, mid/an)
      if idx > i:
        c += idx - i
    
    for i, ap in enumerate(Ap, 1):
      if ap:
        idx = bisect.bisect_right(Ap, mid/ap)
        if idx > i:
          c += idx - i
      else:
        c += Np - i
    
    if c >= k:
      right = mid
    else:
      left = mid
  
  ans = 10**20
  for an in An:
    idx = bisect.bisect_left(An, right/an)
    if idx < Nn:
      ans = min(ans, An[idx]*an)
  for ap in Ap:
    if ap:
      idx = bisect.bisect_left(Ap, right/ap)
      if idx < Np:
        ans = min(ans, Ap[idx]*ap)
    else:
      if right == 0:
        ans = 0
        break

print(ans)