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: Runtime Error

Solution code:
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
mod=pow(10,9)+7

n=input()
lst=[]
for i in range(len(n)):
    lst.append(int(n[i]))
# n=int(n)

keta=len(lst)
ans=0
lst.reverse()

dp=[]
for i in range(keta+1):
    dp.append([float('inf')]*2)
dp[0]=[0,1]
# print(dp)
for i in range(keta):
    dp[i+1][0]=min(dp[i][0]+lst[i],dp[i][1]+lst[i]+1)
    dp[i+1][1]=min(dp[i][0]+(10-lst[i]),dp[i][1]+(10-lst[i]-1))
# print(dp)
print(min(dp[-1][0],dp[-1][1]+1))

Submission status: Runtime Error

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

# process/output
A.sort()

Am = []
A0 = []
Ap = []
i = 0
while A[i] < 0:
    Am.append(A[i])
    i += 1
while A[i] == 0:
    A0.append(A[i])
    i += 1
while i < N:
    Ap.append(A[i])
    i += 1

B = []
if K <= len(Am)*len(Ap):
    for i in range(len(Am)):
        for j in range(len(Ap)):
            B.append(Am[i]*Ap[j])
    B.sort()
    print(B[K-1])

elif K <= len(Am)*len(Ap) + len(A0)*(N-1)//2:
    print(0)

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

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

    B.sort()
    print(B[K-N*(N-1)//2-1])

Submission status: Runtime Error

Solution code:
import bisect
n,k=map(int,input().split())
l=list(map(int,input().split())) 
g=10**18+10
h=-g
while g-h>1:
    u=(g+h)//2
    ka=0
    for i in range(n):
        hi=bisect.bisect_left(l,u//l[i])
        ka+=hi
        if hi>=i:
            ka-=1
    if ka<=u:
        g=u
    else:
        h=u
print(g)

Submission status: Runtime Error

Solution code:
def solve():
    N, K = [int(x) for x in input().split()]
    a_lst = [int(x) for x in input().split()]
    ans = []
    a_lst.sort()
    n_m = n_z = n_p = 0
    a_m = a_z = a_p = 0
    for a in a_lst:
        if a < 0: n_m += 1
        if a == 0: n_z += 1
        if a > 0: n_p += 1
    a_m = n_m * n_p
    a_z = n_z * (n_m + n_p) + n_z * (n_z - 1)//2
    a_p = N*(N-1)//2 - a_m - a_z
    if K <= a_m:
        ans = [0]*a_m
        k = 0
        for i in range(n_m):
            for j in range(n_m + n_z, N):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        ans.sort()
        return ans[K - 1]
    elif a_m < K <= a_m + a_z:
        return 0
    else:
        ans = [0]*a_p
        k = 0
        for i in range(n_m - 1):
            for j in range(i + 1, n_m):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        for i in range(n_m + n_z, N - 1):
            for j in range(i + 1, N):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        ans.sort()
        return ans[K - a_m - a_z - 1]

if __name__ == '__main__':
    print(solve())

Submission status: Runtime Error

Solution code:
n,order = map(int, input().split())
nums = [int(str) for str in input().split()]
maxn = int(n * (n-1) /2)
result = list(range(maxn))
bangou = 0
 
for x in range(n-1):
  for y in range(n-x-1):
    result[bangou] = int( nums[x] * nums[x + y + 1] )
    bangou += 1

result.sort()
print(result[order-1])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;

int n, k, tmp;
vector<int> v, compV;

int main() {
	cin>>n>>k;
	for(int i=0; i<n; i++){
		cin>>tmp;
		v.push_back(tmp);
	}
	
	int comp;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			comp = v[i]*v[j];
			// cout<<"comp:"<<comp<<endl;
			compV.push_back(comp);
		}
	}
	
	sort(compV.begin(), compV.end());
	
	cout<<compV[k];
	return 0;
}

Submission status: Runtime Error

Solution code:
from itertools import combinations
N, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
A = np.array(A)
over_0 = A[A > 0]
under_0 = A[A < 0]
zero = A[A == 0]
minus = len(over_0) * len(under_0)
between_zero = minus + len(over_0) * len(zero) + len(under_0) * len(zero) + (len(zero)*(len(zero)-1)/2)
if minus >= K:
    a = len(minus_0) // K
    b = len(minus_0) % K
    answer = over_0[a] * minus_0[b-1]
elif minus < K and K <= between_zero:
    answer = 0
else:
    answer = sorted(list(map(multiply, combinations(over_0, r=2))) + list(map(multiply, combinations(under_0, r=2))))[K-int(between_zero) -1 ]
print(answer)

Submission status: Runtime Error

Solution code:
N,K = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
for i in range(N):
    if A[i] >= 0:
        s = i
        break
    s = N-1
for i in range(N-1,-1,-1):
    if A[i] <= 0:
        t = N-1-i
        break
    t = 0
r = N-t-s
S = A[:s]
T = A[-t:]
if s*t < K and K < s*t + r*(t+s)+r*(r-1)//2+1:
    print(0)
if K <= s*t:
    B = []
    for a in S:
        for b in T:
            B.append(a*b)
    print(sorted(B)[K-1])
else:
    B = []
    for i in range(s):
        for j in range(i+1,s):
            B.append(S[i]*S[j])
    for i in range(t):
        for j in range(i+1,t):
            B.append(T[i]*T[j])
    print(sorted(B)[K-s*t - r*(t+s)-r*(r-1)//2-1])

Submission status: Runtime Error

Solution code:
n,k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*int(n*(n-1)/2)
x=0
y=1
for i in range(len(l)):
    if(y==n):
        x+=1
        y=x+1
    l[i] = a[x]*a[y]
    y+=1
l.sort()
print(l[k-1])

Submission status: Runtime Error

Solution code:

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

for i in range(n):
    for j in range(i,n):
        if i != j:
            b.append(a[i]*a[j])
b.sort()
print(b)
print(b[k])

Submission status: Runtime Error

Solution code:
N, K = list(map(int, input().split()))
S = list(map(int, input().split()))
A = []
B = []
C = []
for i in range(N):
    t = S[i]
    if 0 < t:
        A.append(t)
    elif 0 == t:
        C.append(t)
    else:
        B.append(t)

if K <= len(A)*len(B):
    L = []
    for i in range(len(A)):
        for j in range(len(B)):
            L.append(A[i]*B[j])
    L.sort()
    print(L[K-1])
    exit()

elif len(A)*len(B) < K <= len(A)*len(B)+(len(C)*(len(A)+len(B)-1)):
    print(0)
    exit()

else:
    L = []
    for i in range(len(A)-1):
        for j in range(len(A)-i-1):
            L.append(A[i]*A[i+j+1])
    for i in range(len(B)-1):
        for j in range(len(B)-i-1):
            L.append(B[i]*B[i+j+1])
    L.sort()
    print(L[K-1-len(A)*len(B)-(len(C)*(len(A)+len(B)-1))])

Submission status: Runtime Error

Solution code:
import numpy as np

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

Aarray = np.matrix([A], dtype=float)
mulA = np.array(Aarray.T * Aarray)

mul_list = []
for i in range(N):
    mul_list += mulA[i,(i+1):].tolist()

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import itertools

N, K = map(int, input().split())
numlist = list(map(int, input().split()))
pemlist = list(itertools.combinations(numlist, 2))

mullist = []
for i in range(len(pemlist)):
  a =pemlist[i][0]*pemlist[i][1]
  mullist.append(a)

finlist =sorted(mullist)
print(finlist[K])

Submission status: Runtime Error

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

over0 = [i for i in a if i>0]
under0 = [i for i in a if i<0]
numover0 = len(over0)
numunder0 = len(under0)
num0 = len(a) - numover0 - numunder0
l=[]
if k <= numover0 * numunder0: # under 0
  for o in over0:
    for u in under0:
      l.append(o*u)
  print(sorted(l)[k-1])
  #under 0
elif k<= numover0 * numunder0 + num0 * (numover0+numunder0): # 0
  print(0)
else: # over 0
  #over 0
  for i in range(numover0-1):
    for j in range(i+1,numover0):
      l.append(over0[i]*over0[j])
  for i in range(numunder0-1):
    for j in range(i+1,numunder0):
      l.append(under0[i]*under0[j])
  print(sorted(l,reverse=True)[len(a)*(len(a)-1)//2-k])

Submission status: Runtime Error

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 = 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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

N, K = np.fromstring(input(), int, sep=" ")
As = np.fromstring(input(), np.int64, sep=" ")

# i, j = np.tril_indices(N, -1)
# print(sorted(As[i] * As[j])[K-1])


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


pos = As[As > 0]
neg = As[As < 0]

n_pos = count_combination(len(pos)) + count_combination(len(neg))
n_neg = len(pos) * len(neg)
n_zero = count_combination(N) - (n_pos + n_neg)


if K <= n_neg:
    mul = (pos[:, None] * neg[None, :]).flatten()
    print(sorted(mul)[K - 1])

elif K <= n_neg + n_zero:
    print(0)

else:
    i, j = np.tril_indices(len(pos), -1)
    mul_pos = pos[i] * pos[j]

    i, j = np.tril_indices(len(neg), -1)
    mul_neg = neg[i] * neg[j]

    cat = np.concatenate((mul_pos, mul_neg))
    cat.sort()

    print(cat[K - 1 - n_neg - n_zero])

Submission status: Runtime Error

Solution code:
N,K=map(int,input().split())
A,B,C,X=[],[],[],[]
for i in range(N):
    a=int(input())
    if a==0:
        B.append(a)
    elif a<0:
        A.append(a)
    else:
        C.append(a)
D=len(A)*len(C)
if D>=K:
    for a in (A):
        for c in (C):
            d=a*c
            X.append(d)
    X.sort()
    print(X[K])
elif D+len(B)>=K:
    print(0)
else:
    E=K-D-len(B)
    for a in (A):
        for c in (A):
            d=a*c
            X.append(d)
    for a in (C):
        for c in (C):
            d=a*c
            X.append(d)
    X.sort()
    print(X[E])

Submission status: Runtime Error

Solution code:
n,k=map(int,input().split())
A=[int(i) for i in input().split()]
A.sort()
neg,zer,pos=0,0,0
for a in A:
  if a<0:
    neg+=1
  elif a==0:
    zer+=1
  else:
    pos+=1
N,P=A[:neg],A[neg+zer:]
import bisect

a=neg*pos
b=a+zer*(neg+pos)+zer*(zer-1)//2

if k<=a:
  l,r=N[0]*P[-1],N[-1]*P[0]
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=(-mid)//nn
      ct+=pos-bisect.bisect_right(P,x)
    if ct>=k:
      r=mid
    else:
      l=mid
  print(r)
elif k<=b:
  print(0)
else:
  k-=b
  l,r=min(N[-1]**2,P[0]**2),max(N[0]**2,P[-1]**2)
  while r-l>1:
    mid=(l+r)//2
    ct=0
    for nn in N:
      nn=-nn
      x=mid//nn
      ct+=neg-bisect.bisect_left(N,-x)
      if nn**2<=mid:
        ct-=1
    for pp in P:
      x=mid//pp
      ct+=bisect.bisect_right(P,x)
      if pp**2<=mid:
        ct-=1
    if ct>=2*k:
      r=mid
    else:
      l=mid
  print(r)

Submission status: Runtime Error

Solution code:
import itertools


n, k = map(int, input().split())
p = list(map(int, input().split()))
# s = input().split()
# S = [int(input()) for i in range(int(n))]

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

print(sorted(result)[k])

Submission status: Runtime Error

Solution code:
def K2last_naive2(K, A1, A2):
    products = []
    for a1 in A1:
        for a2 in A2:
            products.append(a1 * a2)
    products.sort()
    return products[K - 1]

def K2last(N, K, A):
    for n in range(N):
        if A[n] > 0:
            n_first_pos = n
            break
    num_negs = n_first_pos * (N - n_first_pos)
    if K <= num_negs:
        # negative range
        return K2last_naive2(K, A[0:n_first_pos], A[n_first_pos:])
    else:
        # positive range
        K -= num_negs
        A_neg = A[:n_first_pos]
        A_pos = A[n_first_pos:]
        products = []
        for i in range(len(A_neg)):
            for j in range(i + 1, len(A_neg)):
                products.append(A_neg[i] * A_neg[j])
        for i in range(len(A_pos)):
            for j in range(i + 1, len(A_pos)):
                products.append(A_pos[i] * A_pos[j])
        products.sort()
        return products[K - 1]

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

main()

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<algorithm>
#include<utility>
#define ttn 1000000000LL
using namespace std;


int main() {
	long long n, k, a[200000];
	cin >> n >> k;
	for(int i = 0; i < n; i++)
		cin >> a[i];
	sort(a, a + n);
	long long l = -ttn * ttn, u = ttn * ttn + 1;
	while(l + 1 != u) {
		long long b = (l + u) / 2;
		long long s = 0;
		for(int i = 0; i < n - 1; i++) {
			long long ai = a[i];
			if (ai < 0) {
				int jl = n-1;
				if (ai * a[jl] > b) {
					continue;
				}
				int ju = i+1;
				if (ai * a[ju] <= b) {
					s += n - i - 1;
					continue;
				}
				while(ju + 1 != jl) {
					int j = (ju + jl) / 2;
					if (ai * a[j] <= b) {
						jl = j;
					} else {
						ju = j;
					}
				}
				s += n-jl;
			} else {
				int jl = i + 1;
				if (ai * a[jl] > b) {
					continue;
				}
				int ju = n - 1;
				if (ai * a[ju] <= b) {
					s += n - i - 1;
					continue;
				}
				while(jl + 1 != ju) {
					int j = (jl + ju) / 2;
					if (ai * a[j] <= b) {
						jl = j;
					} else {
						ju = j;
					}
				}
				s += jl - i;
			}
		}
		if (s < k) {
			l = b;
		} else {
			u = b;
		}
	}
	cout << u << endl;
}

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys

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



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

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

negatives = []
zeros = []
positives = []
tmp = []

for i in arr:
  if i < 0:
    negatives.append(i)
  elif i == 0:
    zeros.append(i)
  else:
    positives.append(i)

negatives.sort()
zeros.sort()
positives.sort()

ngs = len(negatives) * len(positives)
if k < ngs:
  for i in range(len(negatives)):
    for j in range(i+1, len(negatives)):
      tmp.append(arr[i] * arr[j])
      if len(tmp) > k: break

  print(tmp[k-1])
  sys.exit()

k = k - ngs

zs = 0
for i in range(len(zeros)):
  zs += len(arr) - i-1

if k < zs:
  print(str(0))
  sys.exit()

k = k - zs

# positives.extend(negatives)
for i in range(len(positives)):
  for j in range(i+1, len(positives)):
    tmp.append(arr[i] * arr[j])

import pdb; pdb.set_trace()
tmp.sort()
print(tmp[k-1])

Submission status: Runtime Error

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

p = []

total = 0;
r = True
ans = []
for i in range(0,n):
    for j in range(i+1,n):
        ans.append(l[i]*l[j])
        
ans.sort()      
print(ans[k-1])

Submission status: Runtime Error

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

A = sorted(A)
L = []

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

L = sorted(L)

print(L[K-1])

Submission status: Runtime Error

Solution code:
import bisect

def solve():
    N, K = [int(x) for x in input().split()]
    a_lst = [int(x) for x in input().split()]
    ans = []
    a_lst.sort()
    n_m = n_z = n_p = 0
    a_m = a_z = a_p = 0
    for a in a_lst:
        if a < 0: n_m += 1
        if a == 0: n_z += 1
        if a > 0: n_p += 1
    a_m = n_m * n_p
    a_z = n_z * (n_m + n_p) + n_z * (n_z - 1)//2
    a_p = N*(N-1)//2 - a_m - a_z
    if K <= a_m:
        ans = [0]*a_m
        k = 0
        for i in range(n_m):
            for j in range(n_m + n_z, N):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        ans.sort()
        return ans[K - 1]
    if a_m < K <= a_m + a_z:
        return 0
    else:
        ans = [0]*a_p
        k = 0
        for i in range(n_m):
            for j in range(i + 1, n_m):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        for i in range(n_m + n_z, N - 1):
            for j in range(i + 1, N):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        ans.sort()
        return ans[K - a_m - a_z - 1]

if __name__ == '__main__':
    print(solve())

Submission status: Runtime Error

Solution code:
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
npa = np.array(a)
npb = npa.reshape(n,1)
p = [np.tril(np.full((n,n),1),k=-1)==1]
a = (npa*npb)[p]
a.sort()
print(a[k-1])

Submission status: Runtime Error

Solution code:
import numpy as np

N, K = np.fromstring(input(), int, sep=" ")
# As = np.fromstring(input(), np.int64, sep=" ")
As = list(map(int, input().split()))

# i, j = np.tril_indices(N, -1)
# print(sorted(As[i] * As[j])[K-1])

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


print("debug")

pos = As[As > 0]
neg = As[As < 0]

n_pos = count_combination(len(pos)) + count_combination(len(neg))
n_neg = len(pos) * len(neg)
n_zero = count_combination(N) - (n_pos + n_neg)


if K <= n_neg:
    n, m = max(n_pos, n_neg), min(n_pos, n_neg)
    i, j = np.tril_indices(n, -1, m)
    print(sorted(As[i] * As[j])[K - 1])

elif K <= n_neg + n_zero:
    print(0)

else:
    i, j = np.tril_indices(len(pos), -1)
    mul_pos = pos[i] * pos[j]

    i, j = np.tril_indices(len(neg), -1)
    mul_neg = neg[i] * neg[j]

    cat = np.concatenate((mul_pos, mul_neg))
    cat.sort()

    print(cat[K - 1 - n_neg - n_zero])

Submission status: Runtime Error

Solution code:
import bisect

def solve():
    N, K = [int(x) for x in input().split()]
    a_lst = [int(x) for x in input().split()]
    ans = []
    a_lst.sort()
    n_m = n_z = n_p = 0
    a_m = a_z = a_p = 0
    for a in a_lst:
        if a < 0: n_m += 1
        if a == 0: n_z += 1
        if a > 0: n_p += 1
    a_m = n_m * n_p
    a_z = n_z * (n_m + n_p) + n_z * (n_z - 1)//2
    a_p = N*(N-1)//2 - a_m - a_z
    print(K, a_m, a_m + a_z)
    if K <= a_m:
        ans = [0]*a_m
        k = 0
        for i in range(n_m):
            for j in range(n_m + n_z, N):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        ans.sort()
        return ans[K - 1]
    if a_m < K <= a_m + a_z:
        return 0
    else:
        ans = [0]*a_p
        k = 0
        for i in range(n_m):
            for j in range(i + 1, n_m):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        for i in range(n_m + n_z, N - 1):
            for j in range(i + 1, N):
                ans[k] = a_lst[i] * a_lst[j]
                k += 1
        ans.sort()
        return ans[K - a_m - a_z - 1]

if __name__ == '__main__':
    print(solve())

Submission status: Runtime Error

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 = 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-seihu_cnt-zero_cnt])
    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: Runtime Error

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

size = n*(n-1)//2

asort = np.sort(a)
x = np.multiply.outer(asort, asort)
xtril = np.tril(x, -1)

xunder0 = np.sort(xtril[xtril < 0])
xunsize = xunder0.size
xupper0 = np.sort(xtril[xtril > 0])
xupsize = xupper0.size
x0size = size - xunsize - xupsize
### print(x0size, xunsize, xupsize) ###

if k <= xunsize:
    print(xunder0[k-1])
elif k <= xunsize + x0size:
    print(0)
else:
    print(xupper0[k-xunsize-x0size-1])

Submission status: Runtime Error

Solution code:
» head d/run.py
from itertools import combinations

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

def calc_regular(N, s, A):
    items = []
    for k1, k2 in combinations(range(N), 2):
        v = A[k1] * A[k2]
        if len(items) < s:
            items.append(v)
            items.sort()
        elif items[-1] > v:
            items.append(v)
            items.sort()
            del items[-1]
        else:
            pass
    return items[-1]


def calc_reverse(N, s, A):
    items = []
    for k1, k2 in combinations(range(N), 2):
        v = A[k1] * A[k2]
        if len(items) < s:
            items.append(v)
            items.sort(reverse=True)
        elif items[-1] <= v:
            items.append(v)
            items.sort(reverse=True)
            del items[-1]
        else:
            pass
    return items[-1]


Kmax = N * (N - 1) / 2
if Kmax / 2 >= K:
    print(calc_regular(N, K, A))
else:
    print(calc_reverse(N, Kmax - K + 1, A))

Submission status: Runtime Error

Solution code:
N, K = map(int, input().split())
a = [0] * N
cnst = N * (N - 1) // 2
b = [0] * cnst
a = list(map(int, input().split()))
    
cnt = 0
for i in range(N):
    for j in range(i+1, N):
        b[cnt] = a[i] * a[j]
        cnt += 1
b.sort()

print(b[K-1])

Submission status: Runtime Error

Solution code:
n, k =(int(x) for x in input().split())
    a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
    num = 0

    lis = []

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

    print(lis[k-1])

Submission status: Runtime Error

Solution code:
import numpy as np

N, K = np.fromstring(input(), int, sep=" ")
As = np.fromstring(input(), np.int64, sep=" ")

# i, j = np.tril_indices(N, -1)
# print(sorted(As[i] * As[j])[K-1])

print("debug")

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


pos = As[As > 0]
neg = As[As < 0]

n_pos = count_combination(len(pos)) + count_combination(len(neg))
n_neg = len(pos) * len(neg)
n_zero = count_combination(N) - (n_pos + n_neg)


if K <= n_neg:
    n, m = max(n_pos, n_neg), min(n_pos, n_neg)
    i, j = np.tril_indices(n, -1, m)
    print(sorted(As[i] * As[j])[K - 1])

elif K <= n_neg + n_zero:
    print(0)

else:
    i, j = np.tril_indices(len(pos), -1)
    mul_pos = pos[i] * pos[j]

    i, j = np.tril_indices(len(neg), -1)
    mul_neg = neg[i] * neg[j]

    cat = np.concatenate((mul_pos, mul_neg))
    cat.sort()

    print(cat[K - 1 - n_neg - n_zero])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np

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

info.sort()
another_info = info.copy()



info = np.array(info)
another_info = np.array(another_info)

info = info.reshape(n,1)
another_info = another_info.reshape(1, n)

ans_arr = info * another_info
ans_arr = ans_arr.reshape(1, n**2)


ans_arr = ans_arr.tolist()

print(ans_arr)
ans_arr[0].sort()
print(ans_arr[0][2*(k-1)])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
l = list(map(int,input()))


l.reverse()
l.append(0)

l_copy = l.copy()

N = len(l)

pay = []
for i in range(N):
    if l[i] <= 5:
        pay.append(l[i])
    if 10 > l[i] > 5:
        pay.append(0)
        l[i+1] += 1
    if l[i] == 10:
        pay.append(0)
        l[i+1] += 1

pay_copy = pay.copy()

remain = []
for i in range(N):
    k = pay[i] - l_copy[i]
    if  k >= 0:
        remain.append(k)
    else:
        remain.append(k+10)
        pay[i+1] -= 1

result = 0
for i in pay_copy:
    result += i
for i in remain:
    result += i

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
n, k = map(int, input().split())
a = list(map(int, input().split()))
np_a = np.array(a)
ans = []
seki = np.reshape(np_a, (n,1)) * np_a

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

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

Submission status: Runtime Error

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 = 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-seihu_cnt-zero_cnt])
    elif K <= seihu_cnt+zero_cnt:
        print(0)
    else:
        for a,b in combinations(sei, 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: Runtime Error

Solution code:
def solve_dp(s):
    n = len(s)
    s = [int(c) for c in s]
    inf = 10**9

    dp = [[inf] * 2 for _ in range(n)]

    d0 = s[0]
    dp[0][0] = d0
    dp[0][1] = d0+1

    for i in range(1, n):
        for j in range(2):
            d = s[i] + j
            for k in range(10):
                dp[i][j] = min(dp[i][j], dp[i-1][1] + (2*k + d)%10)


    return dp[n-1][0]

if __name__ == '__main__':
    s = input()
    s = "0"+ s
    print(solve_dp(s))

Submission status: Runtime Error

Solution code:
import numpy as np

def numpy_combinations(arr):
  r, c = np.triu_indices(len(arr), 1)
  return arr[r] * arr[c]
 
n,k = [int(i) for i in input().split()]

l = [int(i) for i in input().split()]
p = numpy_combinations(np.array(l))

p = np.sort(p)

print(p[k-1])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
npa = np.array(a)
npb = npa.reshape(n,1)
p = np.full((n,n),1)
p2 = np.tril(p,k=-1)
p3 = [p2==1]
x = npa*npb
a = x[p3]
a.sort()
print(a[k-1])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>

using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;
    int a[n]; 
    vector<int> ans;

    for (int  i = 0; i < n; i++){ 
        cin >> a[i];
    }
    //cout <<"n:" <<n  << endl;
    
    for (int i = 0; i < n; i++){ 
        for (int j = i+1; j < n; j++){
            //cout << i << " "<< j << endl;
            ans.push_back(a[i] * a[j]);
        }
    }
    sort(ans.begin(), ans.end());

    cout << ans[k] << endl;

    
    return 0;
}

Submission status: Runtime Error

Solution code:
import numpy as np

N, K = np.fromstring(input(), int, sep=" ")
# As = np.fromstring(input(), np.int64, sep=" ")
As = list(map(int, input().split()))
As = np.array(As)

# i, j = np.tril_indices(N, -1)
# print(sorted(As[i] * As[j])[K-1])


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


pos = As[As > 0]
neg = As[As < 0]

n_pos = count_combination(len(pos)) + count_combination(len(neg))
n_neg = len(pos) * len(neg)
n_zero = count_combination(N) - (n_pos + n_neg)


if K <= n_neg:
    n, m = max(n_pos, n_neg), min(n_pos, n_neg)
    i, j = np.tril_indices(n, -1, m)
    print(sorted(As[i] * As[j])[K - 1])

elif K <= n_neg + n_zero:
    print(0)

else:
    i, j = np.tril_indices(len(pos), -1)
    mul_pos = pos[i] * pos[j]

    i, j = np.tril_indices(len(neg), -1)
    mul_neg = neg[i] * neg[j]

    cat = np.concatenate((mul_pos, mul_neg))
    cat.sort()

    print(cat[K - 1 - n_neg - n_zero])