Problem p02883 (python)

Fixed submission:
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=-1
    right=10**12
    prev_x=-10
    # 二分探索でtest(x)がtrueとなるxの最小値を探索する
    # left = rightとなるまで繰り返す
    while left + 1 < right:
      mid = (left+right)//2
      
      # mid秒で食べられる場合は探索範囲の右端をmidにする
      if can_eat_by(mid):
        right = mid
      # mid秒で食べられない場合は探索範囲の左端をmidにする
      else:
        left = mid
     
    answer = right
    print(answer)

main()

Buggy submission (verdict: Runtime Error):
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=-1
    right=10**12
    prev_x=-10
    while True:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
        if abs(next_x-prev_x)<=1:
            break
        prev_x=next_x
    print(answer)

main()

Buggy submission (verdict: Runtime Error):
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=0
    right=10**12
    prev_x=-10
    while True:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
        if abs(next_x-prev_x)<=1:
            break
        prev_x=next_x
    print(answer)

main()

Buggy submission (verdict: Runtime Error):
def main():
    N,K=map(int,input().split())
    a_ls=list(map(int,input().split()))
    f_ls=list(map(int,input().split()))
    
    a_ls.sort()
    f_ls.sort()
    f_ls.reverse()
    
    def can_eat_by(x):
        cost_after_training=list(map(lambda item: x//item, f_ls))
        sum=0
        for i in range(N):
            if a_ls[i]>cost_after_training[i]:
                sum+=a_ls[i]-cost_after_training[i]
        return sum<=K
    
    left=0
    right=10**12
    prev_x=-10
    while True:
        next_x=(right+left)//2
        if can_eat_by(next_x):
            answer=next_x
            right=next_x
        else:
            left=next_x
        if abs(next_x-prev_x)<=1:
            break
        prev_x=next_x
    print(answer)

main()

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
a_ls=list(map(int,input().split()))
f_ls=list(map(int,input().split()))

a_ls.sort()
f_ls.sort()
f_ls.reverse()

def can_eat_by(x):
    cost_after_training=list(map(lambda item: x//item, f_ls))
    sum=0
    for i in range(N):
        if a_ls[i]>cost_after_training[i]:
            sum+=a_ls[i]-cost_after_training[i]
    return sum<=K

left=0
right=10**12
prev_x=-10
while True:
    next_x=(right+left)//2
    if can_eat_by(next_x):
        answer=next_x
        right=next_x
    else:
        left=next_x
    if abs(next_x-prev_x)<=1:
        break
    prev_x=next_x
print(answer)