Problem p02774 (python)

Fixed submission:
import numpy as np
from numba import njit
N,K=[int(_) for _ in input().split()]
A = np.array([int(_) for _ in input().split()],dtype=int)
A.sort()


@njit
def main(N,K,A):
    lb = -10**18-1
    rb = 10 ** 18 + 1
    while rb - lb > 1:
        target = (rb + lb) // 2
        if 1:
            cnt=0
            for i, a in enumerate(A):
                if a==0:
                    d = i if target >= 0 else 0
                elif a < 0:
                    il = np.searchsorted(A,0- (-target)//a,side='left')
                    d = max(i - il, 0)
                else:
                    ir = np.searchsorted(A,target//a,side='right')
                    d = min(ir, i)
                cnt+=d
        if cnt>=K:
            rb = target
        else:
            lb = target
    return rb

print(main(N,K,A))

Buggy submission (verdict: Runtime Error):
import numpy as np
from numba import njit


@njit
def main(I):
    N,K=I[0],I[1]
    A = np.array(I[2:],dtype=int)
    A.sort()
    lb = -10**18-1
    rb = 10 ** 18 + 1
    while rb - lb > 1:
        target = (rb + lb) // 2
        if 1:
            cnt=0
            for i, a in enumerate(A):
                if a==0:
                    d = i if target >= 0 else 0
                elif a < 0:
                    il = np.searchsorted(A,0- (-target)//a,side='left')
                    d = max(i - il, 0)
                else:
                    ir = np.searchsorted(A,target//a,side='right')
                    d = min(ir, i)
                cnt+=d
        if cnt>=K:
            rb = target
        else:
            lb = target
    return rb

I=np.array([int(_) for _ in open(0).read().split()],dtype=int)
print(main(I))

Buggy submission (verdict: Runtime Error):
import bisect
import numpy as np
from numba import njit
N,K=[int(_) for _ in input().split()]
if N==4:
    raise
A = np.array([int(_) for _ in input().split()],dtype=int)
A.sort()
#A=sorted([int(_) for _ in input().split()])

#target以下の積がK個以上ある最小のtarget

@njit
def main(N,K,A):
    lb = -10**18-1
    rb = 10 ** 18 + 1
    # Min x for check(x) == True
    while rb - lb > 1:
        target = (rb + lb) // 2
        if 1:
            cnt=0
            for i, a in enumerate(A):
                if a==0:
                    d = i if target >= 0 else 0
                    cnt+=d
                    continue
                q,r=divmod(target,a)
                if a < 0:
                    #il = bisect.bisect_left(A,  q+(r>0))
                    #il = bisect.bisect_left(A,  target / a)
                    il = np.searchsorted(A,q+(r>0),side='left')
                    #ilからiまで、ただしilがiを超えたら0
                    d = max(i - il, 0)
                else:
                    #ir = bisect.bisect_right(A, q)
                    #ir = bisect.bisect_right(A, target / a)
                    ir = np.searchsorted(A,q,side='right')
                    #0からirまで、ただしirがiを超えたらi
                    d = min(ir, i)
                #print(target,a,d)
                cnt+=d
        if cnt>=K:
            rb = target
        else:
            lb = target
    return rb

print(main(N,K,A))

Buggy submission (verdict: Runtime Error):
#import bisect
import numpy as np
from numba import njit
N,K=[int(_) for _ in input().split()]
if N==4:
    raise
A = np.array([int(_) for _ in input().split()],dtype=int)
#A.sort()
#A=sorted([int(_) for _ in input().split()])

#target以下の積がK個以上ある最小のtarget

@njit
def main(N,K,A):
    lb = -10**18-1
    rb = 10 ** 18 + 1
    # Min x for check(x) == True
    while rb - lb > 1:
        target = (rb + lb) // 2
        if 1:
            cnt=0
            for i, a in enumerate(A):
                if a==0:
                    d = i if target >= 0 else 0
                    cnt+=d
                    continue
                q,r=divmod(target,a)
                if a < 0:
                    #il = bisect.bisect_left(A,  q+(r>0))
                    #il = bisect.bisect_left(A,  target / a)
                    il = np.searchsorted(A,q+(r>0),side='left')
                    #ilからiまで、ただしilがiを超えたら0
                    d = max(i - il, 0)
                else:
                    #ir = bisect.bisect_right(A, q)
                    #ir = bisect.bisect_right(A, target / a)
                    ir = np.searchsorted(A,q,side='right')
                    #0からirまで、ただしirがiを超えたらi
                    d = min(ir, i)
                #print(target,a,d)
                cnt+=d
        if cnt>=K:
            rb = target
        else:
            lb = target
    return rb

print(main(N,K,A))

Buggy submission (verdict: Runtime Error):
import bisect
#import numpy as np
N,K=[int(_) for _ in input().split()]
if N==4:
    raise
#A = np.array([int(_) for _ in input().split()],dtype=int)
#A.sort()
A=sorted([int(_) for _ in input().split()])

#target以下の積がK個以上ある最小のtarget


lb = -10**18-1
rb = 10 ** 18 + 1
# Min x for check(x) == True
while rb - lb > 1:
    target = (rb + lb) // 2
    if 1:
        cnt=0
        for i, a in enumerate(A):
            if a==0:
                d = i if target >= 0 else 0
                cnt+=d
                continue
            q,r=divmod(target,a)
            if a < 0:
                il = bisect.bisect_left(A,  q+(r>0))
                #il = bisect.bisect_left(A,  target / a)
                #il = np.searchsorted(A,target/a,side='left')
                #ilからiまで、ただしilがiを超えたら0
                d = max(i - il, 0)
            else:
                ir = bisect.bisect_right(A, q)
                #ir = bisect.bisect_right(A, target / a)
                #ir = np.searchsorted(A,target/a,side='right')
                #0からirまで、ただしirがiを超えたらi
                d = min(ir, i)
            #print(target,a,d)
            cnt+=d
    if cnt>=K:
        rb = target
    else:
        lb = target
print(rb)

Buggy submission (verdict: Runtime Error):
import bisect
#import numpy as np
N,K=[int(_) for _ in input().split()]
if N==4:
    raise
#A = np.array([int(_) for _ in input().split()],dtype=int)
#A.sort()
A=sorted([int(_) for _ in input().split()])

#target以下の積がK個以上ある最小のtarget

def check(target):
    cnt=0
    for i, a in enumerate(A):
        if a < 0:
            il = bisect.bisect_left(A,  target / a)
            #il = np.searchsorted(A,target/a,side='left')
            #ilからiまで、ただしilがiを超えたら0
            d = max(i - il, 0)
        elif a > 0:
            ir = bisect.bisect_right(A, target / a)
            #ir = np.searchsorted(A,target/a,side='right')
            #0からirまで、ただしirがiを超えたらi
            d = min(ir, i)
        else:
            d = i if target >= 0 else 0
        #print(target,a,d)
        cnt+=d
    return cnt>=K

lb = -10**18-1
rb = 10 ** 18 + 1
# Min x for check(x) == True
while rb - lb > 1:
    mid = (rb + lb) // 2
    if check(mid):
        rb = mid
    else:
        lb = mid
print(rb)

Buggy submission (verdict: Runtime Error):
import bisect
import numpy as np
N,K=[int(_) for _ in input().split()]
if N==4:
    raise
A = np.array([int(_) for _ in input().split()],dtype=int)
A.sort()
#A=sorted([int(_) for _ in input().split()])

#target以下の積がK個以上ある最小のtarget

def check(target):
    cnt=0
    for i, a in enumerate(A):
        if a < 0:
            #il = bisect.bisect_left(A,  target / a)
            il = np.searchsorted(A,target/a,side='left')
            #ilからiまで、ただしilがiを超えたら0
            d = max(i - il, 0)
        elif a > 0:
            #ir = bisect.bisect_right(A, target / a)
            ir = np.searchsorted(A,target/a,side='right')
            #0からirまで、ただしirがiを超えたらi
            d = min(ir, i)
        else:
            d = i if target >= 0 else 0
        #print(target,a,d)
        cnt+=d
    return cnt>=K

lb = -10**18-1
rb = 10 ** 18 + 1
# Min x for check(x) == True
while rb - lb > 1:
    mid = (rb + lb) // 2
    if check(mid):
        rb = mid
    else:
        lb = mid
print(rb)