Problem p03700 (python)

Fixed submission:
import math
"""
def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)

    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
"""
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    arr.append(int(input()))

max_=max(arr)//B+1
min_=min(arr)//A

d=A-B

while min_!=max_:
    mid=(max_+min_)//2
    
    sum_=0
    for x in arr:
        sum_+=max(0,math.ceil((x-mid*B)/d))
        
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

print(min_)

Buggy submission (verdict: Runtime Error):
import math
"""
def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)

    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
"""
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)

max_=max(arr)//B+1
min_=min(arr)//A

d=A-B

while min_!=max_:
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    sum_=0
    for x in tmp:
        sum_+=math.ceil(x/d)
    
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

print(min_)

Buggy submission (verdict: Runtime Error):
import numpy as np
import math
"""
def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)

    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
"""
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)
arr=sorted(arr,reverse=True)
arr=np.array(arr)

max_=arr[0]//B+1
min_=arr[-1]//A

while min_!=max_:
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

ans=search(min_,max_,A,B,arr)

print(ans)

Buggy submission (verdict: Runtime Error):
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)
arr=sorted(arr,reverse=True)
arr=np.array(arr)

max_=arr[0]//B+1
min_=arr[-1]//A

while min_!=max_:
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

ans=search(min_,max_,A,B,arr)

print(ans)

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

def search(min_,max_,A,B,arr):
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr[:]
    tmp+=mid*B
    k=mid
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=tmp[tmp<0]
    L=len(tmp)
    
    while True:
        x=-tmp.pop()
        k-=x//(A-B)+(x%(A-B)>0)
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
            
        
    
N,A,B=list(map(int,input().split()))
arr=[]
sum_=0

for i in range(N):
    h=int(input())
    arr.append(-h)
    sum_+=h
arr=sorted(arr)
arr=np.array(arr)

max_=-arr[0]//B
min_=sum_//(A+(N-1)*B)

ans=search(min_,max_,A,B,arr)

print(ans)

Buggy submission (verdict: Runtime Error):
def search(min_,max_,A,B,arr):
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=np.array(arr)
    tmp+=mid*B
    k=mid
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=list(tmp[tmp<0])
    
    while True:
        x=-tmp.pop()
        k-=x//(A-B)+(x%(A-B)>0)
        if k<0:
            if mid==min_:
                return max_
            else:
                return search(mid,max_,A,B,arr)
        elif len(tmp)==0:
            return search(min_,mid,A,B,arr)
            
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(-h)
arr=sorted(arr)
arr=np.array(arr)

max_=-arr[0]//B
min_=1

ans=search(min_,max_,A,B,arr)

print(ans)