Problem:
 Score : 400 points    Problem Statement You are going out for a walk, when you suddenly encounter N monsters. Each monster has a parameter called health , and the health of the i -th monster is h_i at the moment of encounter. A monster will vanish immediately when its health drops to 0 or below.  Fortunately, you are a skilled magician, capable of causing explosions that damage monsters. In one explosion, you can damage monsters as follows:   Select an alive monster, and cause an explosion centered at that monster. The health of the monster at the center of the explosion will decrease by A , and the health of each of the other monsters will decrease by B . Here, A and B are predetermined parameters, and A > B holds.   At least how many explosions do you need to cause in order to vanish all the monsters?      Constraints  All input values are integers.  1 ≤ N ≤ 10^5  1 ≤ B < A ≤ 10^9  1 ≤ h_i ≤ 10^9         Input Input is given from Standard Input in the following format:  N  A  B  h_1  h_2  :  h_N       Output Print the minimum number of explosions that needs to be caused in order to vanish all the monsters.        Sample Input 1 4 5 3
8
7
4
2      Sample Output 1 2  You can vanish all the monsters in two explosion, as follows:   First, cause an explosion centered at the monster with 8 health. The healths of the four monsters become 3 , 4 , 1 and -1 , respectively, and the last monster vanishes.  Second, cause an explosion centered at the monster with 4 health remaining. The healths of the three remaining monsters become 0 , -1 and -2 , respectively, and all the monsters are now vanished.        Sample Input 2 2 10 4
20
20      Sample Output 2 4  You need to cause two explosions centered at each monster, for a total of four.       Sample Input 3 5 2 1
900000000
900000000
1000000000
1000000000
1000000000      Sample Output 3 800000000

Solution (Python):
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()

ans = 0
l, r = 1, max(h)//B+1
while l < r:
    m = (l+r)//2
    c = m
    for i in range(N):
        t = h[i]-m*B
        if t > 0:
            c -= (t+A-B-1)//(A-B)
            if c < 0:
                break

    if c >= 0:
        r = m
    else:
        l = m+1

print(l)

Solution (Python):
import math
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]

x = A-B

def func(cnt):
    dmg = B*cnt
    tmp = [max(0, val-dmg) for val in h]
    cnt2 = sum([math.ceil(val/x) for val in tmp])
    if cnt2 > cnt:
        return False
    else:
        return True

ok = 10**9 
ng = 0 
while abs(ok-ng) > 1:
    cnt = (ok + ng) // 2
    if func(cnt):
        ok = cnt
    else:
        ng = cnt
print(ok)

Solution (Python):
n,a,b = map(int,input().split())
H = [int(input()) for _ in range(n)]

def ok(x):
    cnt = 0
    for h in H:
        cnt += max(0, (h - b*x-1)//(a-b)+1)
    return cnt <= x

top = 10**9
bottom = 0
while top - bottom > 1:
    mid = (top + bottom)//2
    if ok(mid):
        top = mid
    else:
        bottom = mid
print(top)

Solution (Python):
from math import ceil
def f(x,hp):
  hp=[hh-(b*x) for hh in hp]
  c=0
  for p in hp:
    if p<=0:continue
    c+=ceil(p/(a-b))
  return c<=x

n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
ng=0
ok=10**9
while ok-ng>1:
  mid=(ok+ng)//2
  if f(mid,h):
    ok=mid
  else:
    ng=mid
print(ok)

Solution (Python):

n, a, b = map(int, input().split())

monster = []
for i in range(n):
    monster.append(int(input()))

def damage(monster, t):
    temp = []
    for hp in monster:
        s = hp - t * b
        if s > 0:
            temp.append(s)
    ans = 0
    for hp in temp:
        if hp % (a - b) != 0:
            ans += 1
        ans += hp // (a - b)
    return True if ans <= t else False

ans = float('inf')
l = 0
r = 10 ** 9
while l <= r:
    mid = (l + r) // 2
    if damage(monster, mid):
        ans = min(ans, mid)
        r = mid - 1
    else:
        l = mid + 1
print(ans)

Solution (Python):
nim, mike, kite = map(int, input().split())
H = [int(input()) for _ in range(nim)]
C = mike - kite
l, r = 0, 1<<30
while r - l > 1:
    m = (l + r) // 2
    if sum([max((h - kite * m + C - 1) // C, 0) for h in H]) <= m:
        r = m
    else:
        l = m
print(r)

Solution (Python):
import math
import io

nim, mike, kite = map(int, input().split())
H = [int(input()) for _ in range(nim)]

OK = max(H)//kite+1
NG = 0

ans = OK
while OK-NG > 1:
    mid = (OK+NG)//2  
    cnt = 0

    for h in H:
        if h > mid*kite:
            cnt += math.ceil((h-mid*kite)/(mike-kite))

    if cnt <= mid:
        OK = mid
    else:
        NG = mid

print(OK)

Solution (Python):


import math


N, A, B = map(int, input().split())
h_list = [0]*N
for i in range(N):
    h = int(input())
    h_list[i] = h


left = 0
right = 10**10


while right-left>1:
    mid = (right + left) // 2

    
    count = 0
    for h in h_list:
        h = h - B * mid

        if h<0:
            h = 0

        tmp_count = math.ceil(h / (A - B))
        count += tmp_count

    if count>mid:
        left = mid
    else:
        right = mid


print(right)

Solution (Python):
import sys
input = sys.stdin.readline

n,a,b= map(int, input().split())
h= [int(input()) for i in range(n)]



l=-1
r=pow(10,10)
while r-l>1:
    
    mid=l+(r-l)//2
    
    x=mid
    
    for i in range(n):
        
        if mid*b>=h[i]:
            continue
        else:
            
            y=-(-(h[i]-(mid*b))//(a-b))
            x-=y
            if x<0:
                break
    if x>=0:
        r = mid  
    else:
        l=mid 

print(r)

Solution (Python):
from math import ceil
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]

def can_beet(t):
    ans = False
    d = 0
    for v in h:
        sub = v - (b * t)
        if sub > 0:
            d += ceil(sub / (a - b))
    if d <= t:
        ans = True
    return ans

l = -1
r = 10 ** 9 + 1
while r - l > 1:
    mid = (r + l) // 2
    if can_beet(mid):
        r = mid
    else:
        l = mid
print(r)

Solution (Python):

from math import ceil
n, a, b = map(int, input().split()) 


monster = []
for i in range(n):
    monster.append(int(input()))

def check(monster, t):
    temp = []
    for i in range(n):
        temp.append(monster[i] - b * t) 
    ans = 0
    for i in range(n):
        if temp[i] > 0:
            ans += ceil(temp[i] / (a - b))
    if ans <= t:
        return True
    return False

l = 0
r = 10 ** 10
ans = 10 ** 10
while l <= r:
    mid = (l + r) // 2
    if check(monster, mid):
        ans = min(ans, mid)
        r = mid - 1
    else:
        l = mid + 1
print(ans)

Solution (Python):
n,a,b = [int(x) for x in input().split()]
c = a-b
h = []
for _ in range(n):
    h.append(int(input()))
h.sort()
m = h[-1]
z = 0
import bisect,math
while m-z>1:
    mid = (m+z)//2
    k = bisect.bisect_left(h,b*mid)
    cnt = 0
    for i in range(k,n):
        h2 = h[i]-b*mid
        cnt += math.ceil(h2/c)
    if cnt<=mid:
        m = mid
    else:
        z = mid

print(m)

Solution (Python):


import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) 
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


N, A, B = read_ints()
H, = read_col(N)
H.sort(reverse=True)







def is_ok(c):
    
    bias = c * B
    addit = (A - B)
    c_cnt = c  
    for h in H:
        h -= bias
        if h <= 0:
            return True  
        else:
            c_cnt -= (h - 1) // addit + 1
            if c_cnt < 0:  
                return False
    return True  


def meguru_bisect(ng, ok):
    '''
    define is_okと
    初期値のng,okを受け取り,is_okを満たす最小(最大)のokを返す
    ng ok は  とり得る最小の値-1 とり得る最大の値+1
    最大最小が逆の場合はよしなにひっくり返す
    '''
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    return ok


print(meguru_bisect(-1, 10**9 + 1))

Solution (Python):
import heapq

def check(h, T, A, B):
    
    que = []
    for hi in h:
        if hi - B * T > 0:
            que.append(- hi + B * T)
    que.sort()
    A_count = 0
    for q in que:
        count = (-q + (A - B) - 1) // (A - B)
        A_count += count
    
    return A_count <= T


N, A, B = map(int, input().split(" "))
h = []
for _ in range(N):
    h.append(int(input()))

lower, upper = 0, 10 ** 15

while upper - lower > 1:
    mid = (upper + lower) // 2
    if check(h, mid, A, B):
        upper = mid
    else:
        lower = mid

print(upper)

Solution (Python):
import math
N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]


def enough(T):
    temp = 0
    ch = H[:]
    for h in ch:
        left = h - B*T
        if left > 0:
            temp += (left + A-B-1)//(A-B)
            
            

    if temp > T:
        return False
    else:
        return True


ok = 10**15
ng = 0

while ok - ng > 1:
    mid = (ok + ng)//2
    if enough(mid):
        ok = mid
    else:
        ng = mid
    
print(ok)

Solution (Python):
import math
N,A,B = map(int,input().split())
H = [int(input()) for _ in range(N)]


def enough(T):
    temp = 0
    ch = H[:]
    for h in ch:
        left = h - B*T
        if left > 0:
            
            temp += math.ceil(left/(A-B))
            

    if temp > T:
        return False
    else:
        return True


ok = 10**15
ng = 0

while ok - ng > 1:
    mid = (ok + ng)//2
    if enough(mid):
        ok = mid
    else:
        ng = mid
    
print(ok)

Solution (Python):
import math
n,a,b = map(int,input().split())
H = list(int(input()) for _ in range(n))
l,r = 0, 10**9
d = a-b
while r-l>1:
    mid = (r+l)//2
    tmp = 0
    for h in H:
        if h <= mid*b:
            continue
        tmp += math.ceil((h-mid*b)/d)
    if tmp <= mid:
        r = mid
    else:
        l = mid
print(r)

Solution (Python):
import sys
from bisect import bisect_right


def solve(t):
    global A, B, C
    k = bisect_right(H, B * t)
    cnt = 0
    for i in range(k, N):
        h = H[i]
        h -= B * t
        cnt += (h + C - 1) // C
    return cnt <= t


N, A, B = map(int, input().split())
C = A - B
H = [int(s) for s in sys.stdin.readlines()]

H.sort()




ng = 0
ok = H[-1] // B + 1
k = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Solution (Python):
import sys
from bisect import bisect_right


def solve(t):
    global A, B, C
    k = bisect_right(H, B * t)
    cnt = 0
    for i in range(k, N):
        h = H[i]
        h -= B * t
        cnt += (h + C - 1) // C
    return cnt <= t


N, A, B = map(int, input().split())
C = A - B
H = [int(s) for s in sys.stdin.readlines()]

H.sort()




ng = 0
ok = 10 ** 9 + 1000
k = 0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if solve(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Solution (Python):
import sys
import math
def input():
    return sys.stdin.readline()[:-1]

n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]

low,high=0,10**9+1
while high-low>1:
    mid=(high+low)//2
    cnt=0
    for i in range(n):
        tmp=h[i]-mid*b
        if tmp>0:
            cnt+=math.ceil(tmp/(a-b))
    if cnt<=mid:
        high=mid
    else:
        low=mid
    
print(high)

Solution (Python):
N,A,B = map(int,input().split())
h = [0]*N
for i in range(N):
    h[i] = int(input())



import math

def check(x):
    count = 0
    for i in range(N):
        count += math.ceil(max(h[i] - B * x, 0) / (A - B))
           
    if count <= x:
        return True
    else:
        return False
    
def solve():
    
    left = -1
    right = 10**9+1
    
    while abs(right-left) > 1:
    
        center = (right+left)//2
    
        if check(center) == True:
            right = center
        elif check(center) == False:
            left = center
        
    return right
    
print(solve())

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,a,b = map(int, input().split())
    h = [int(input()) for _ in range(n)]

    
    def check(x):
        cnt = 0
        for i in h:
            nokori = i - b*x
            if nokori > 0:
                cnt += nokori // (a-b)
                if nokori % (a-b) != 0:
                    cnt += 1
            if cnt > x:
                return False
        return True

    l = 0
    r = 10**10
    while r-l > 1:
        mid = (l+r) // 2
        if check(mid):
            r = mid
        else:
            l = mid

    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
def isok(arg):
    count = arg
    for i in range(n):
        if -(-(h[i]-b*arg)//(a-b)) >= 0:
            count -= -(-(h[i]-b*arg)//(a-b))
    if count >= 0:
        return True
    else:
        return False

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if isok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n,a,b = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
print(bisect(0,10**9))

Solution (Python):
def isok(arg):
    count = arg
    for i in range(n):
        if -(-(h[i]-b*arg)//(a-b)) >= 0:
            count -= -(-(h[i]-b*arg)//(a-b))
    if count >= 0:
        return True
    else:
        return False

def bisect(ng, ok):
    while (abs(ok - ng) > 1):
        mid = (ok + ng) // 2
        if isok(mid):
            ok = mid
        else:
            ng = mid
    return ok

n,a,b = map(int,input().split())
h = []
for i in range(n):
    h.append(int(input()))
print(bisect(0,10**9))

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

n,a,b = map(int, input().split())
h = list(int(input()) for i in range(n))

diff = a-b

hmax = max(h)

saiaku = -(-hmax//b)

def isok(ans):
    count = 0
    for i in range(n):
        count += max(-(-(h[i]-b*ans)//diff),0)
    if count > ans:
        return False
    return True

ok = saiaku
ng = -1 

while ok - ng > 1:
    m = (ok+ng)//2
    if isok(m):
        ok = m
    else:
        ng = m
print(ok)

Solution (Python):
from math import ceil
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
def enough(x):
  cnt=0
  for i in range(n):
    if h[i]-x*b<=0:
      continue
    cnt+=ceil((h[i]-x*b)/(a-b))
  if cnt<=x:
    return True
  else:
    return False
l=0
r=10**9
while r-l>1:
  mid=(r+l)//2
  if enough(mid):
    r=mid
  else:
    l=mid
print(r)

Solution (Python):
import sys
input = sys.stdin.readline

N, A, B = map(int, input().split())
H = tuple(int(input()) for _ in range(N))


def ceil(a, b):
    return (a + b - 1) // b


def f(x):
    lst = (max(0, h - x * B) for h in H)
    S = sum(ceil(i, A - B) for i in lst)
    return S <= x


l, r = 0, 10 ** 9
while r - l > 1:
    m = (r + l) // 2
    if f(m):
        r = m
    else:
        l = m
print(r)

Solution (Python):
H = []
N, A, B = map(int, input().split())
for _ in range(N):
    H.append(int(input()))


def ceil(a, b):
    return (a + b - 1) // b


def f(x):
    lst = [max(0, h - x * B) for h in H]
    S = sum(ceil(i, A - B) for i in lst)
    return S <= x


l, r = 0, 10 ** 9
while r - l > 1:
    m = (r + l) // 2
    if f(m):
        r = m
    else:
        l = m
print(r)

Solution (Python):

n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
x = a - b

l, r = 0, 10 ** 9
while r - l > 1:
    k = (r + l) // 2
    
    tmp = sum([max(0, -(-(h[i] - k * b) // x)) for i in range(n)])
    if tmp > k:
        l = k
    else:
        r = k
        
print(r)

Solution (Python):
n,a,b=map(int,input().split())
h=[]
for _ in range(n):
    h.append(int(input()))

lo=0
hi=10**9
while lo<hi:
    md=(lo+hi)//2
    def chk(md):
        d=a-b
        cnt=0
        for i in h:
            i-=md*b
            if i>0:
                cnt+=i//d
                if i%d:
                    cnt+=1
        if cnt<=md:
            return True
        else:
            return False
    if chk(md):
        hi=md
    else:
        lo=md+1
print(lo)

Solution (Python):
n,a,b=map(int,input().split())
H=[0]*n
for i in range(n):
  H[i]=int(input())
ng=-1
ok=10**9+5
while ok-ng>1:
  mid=(ng+ok)//2
  c=0
  for i in range(n):
    c=c+(max(0,H[i]-b*mid+a-b-1)//(a-b))
  if c>mid:
    ng=mid
  else:
    ok=mid
print(ok)

Solution (Python):
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
 
import math
def ok(x):
    t = 0
    for i in range(n):
        r = h[i] - b*x
        if r < 0:
            continue
        else:
            t += math.ceil(r/(a-b))
    if t <= x:
        return True
    else:
        return False
 
l = 0
r = 10**14+1
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(r)

Solution (Python):
def binary_search(c1, c2):
    m = (c1 + c2 + 1) // 2
    if abs(c1 - c2) <= 1:
        return m
    else:
        s = list(h)
        c = 0
        for j in s:
            j -= b * m
            if j > 0:
                c += (a + j - b - 1) // (a - b)
            if c > m:
                break
        if c > m:
            c1 = m
        else:
            c2 = m
        return binary_search(c1, c2)

n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
h.sort()
print(binary_search(0, h[n - 1] + 1))

Solution (Python):
N,A,B = map(int,input().split())

h = []

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

def det(num):
    count = 0
    for i in range(N):
        H = h[i]-B*num
        count += max(0,H//(A-B) + min(1,H%(A-B)))
    if count <= num:
        return True
    else:
        return False

x = 1
y = max(h)

while y - x > 1:
    if det((x+y)//2):
        y = (x+y)//2
    else:
        x = (x+y)//2
    

print(y)

Solution (Python):
import sys
input=sys.stdin.readline
n,a,b = map(int, input().split())
h=[int(input()) for i in range(n)]

def solve(num):
    all_b = num*b
    cnt=0
    for i in range(len(h)):
        rest = h[i] - all_b
        if rest>0:
            cnt+=(rest - 1) // (a-b) + 1
    if cnt <= num:
        return True
    else:
        return False

l=0
r=10**20
while r-l>1:
    mid=(l+r)//2

    if solve(mid):
        r=mid
    else:
        l=mid
print(r)

Solution (Python):
import sys
input=sys.stdin.readline
n,a,b = map(int, input().split())
h=[int(input()) for i in range(n)]

def solve(num):
    all_b = num*b
    cnt=0
    for i in range(len(h)):
        rest = h[i] - all_b
        if rest>0:
            cnt+=(rest - 1) // (a-b) + 1
    if cnt <= num:
        return True
    else:
        return False

import copy
l=0
r=10**10
while r-l>1:
    mid=(l+r)//2

    if solve(mid):
        r=mid
    else:
        l=mid
print(r)

Solution (Python):
import copy

N,A,B=map(int,input().split())
h=[]
for i in range(0,N):
    H=int(input())
    h.append(H)

h.sort()

def condition(num):
    testlist=copy.copy(h)
    for i in range(0,N):
        testlist[i]-=B*num
    count=0
    for i in range(0,N):
        if testlist[i]>0:
            if testlist[i]%(A-B)!=0:
                count+=testlist[i]//(A-B)+1
            else:
                count+=testlist[i]//(A-B)
    return num>=count

start=1
end=10**15
while end-start>1:
    test=(end+start)//2
    if condition(test):
        end=test
    else:
        start=test

if condition(start):
    print(start)
else:
    print(end)

Solution (Python):
import sys
rl = sys.stdin.readline


def solve():
    N, A, B = map(int, rl().split())
    h = [int(rl()) for _ in range(N)]
    ad_d = A - B
    
    def calc(t):
        cnt = 0
        for i in range(N):
            d = h[i] - B * t
            if 0 < d:
                cnt += d // ad_d if d % ad_d == 0 else d // ad_d + 1
        return cnt <= t
    
    ok, ng = 10 ** 9, 0
    while 1 < ok - ng:
        mid = (ok + ng) // 2
        if calc(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
rl = sys.stdin.readline


def solve():
    N, A, B = map(int, rl().split())
    h = [int(rl()) for _ in range(N)]
    ad_d = A - B
    
    def calc(t):
        cnt = 0
        for i in range(N):
            d = h[i] - B * t
            if 0 < d:
                cnt += d // ad_d if d % ad_d == 0 else d // ad_d + 1
        return cnt <= t
    
    ok, ng = 10 ** 9, 0
    while 1 < ok - ng:
        mid = (ok + ng) // 2
        if calc(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    solve()

Solution (Python):
N,A,B = map(int, input().split())
hs = [int(input()) for _ in range(N)]

def f(x):
    """
    xが少ないとfalse
    xが大きいとtrue
    """
    As = [max(0,h-B*x) for h in hs]
    Bs = [-(-a//(A-B)) for a in As]
    
    return sum(Bs) <= x


def  binarySearch(l,r):
    while r - l > 1:
        mid = (l+r)//2
        if f(mid):
            r = mid
        else:
            l = mid
    return r


r = 10**9+1
print(binarySearch(0,r))

Solution (Python):
import sys
input = sys.stdin.readline
INF = 10**20
MOD = 10**9 + 7
import numpy as np

def main():
    n,a,b = map(int,input().split())
    H = np.array([int(input()) for _ in range(n)])

    a -= b
    def ok(x): 
        list = (H - b * x + a - 1)//a
        return sum(list[list>0]) <=  x
    
    l = -1
    r = 10 ** 10
    while r - l > 1:
        mid = (r + l)//2
        if ok(mid):
            r = mid
        else:
            l = mid  
    print(r)

if __name__=='__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
INF = 10**20
MOD = 10**9 + 7
import numpy as np

def main():
    n,a,b = map(int,input().split())
    H = np.array([int(input()) for _ in range(n)])

    a -= b
    def ok(x): 
        list = (H - b * x + a - 1)//a
        return list[list>0].sum() <=  x
    
    l = -1
    r = 10 ** 10
    while r - l > 1:
        mid = (r + l)//2
        if ok(mid):
            r = mid
        else:
            l = mid  
    print(r)

if __name__=='__main__':
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N,A,B=map(int,input().split())
h=[int(input()) for i in range(N)]
h.sort(reverse=1)
l,r=0,10**9
k=A-B
while l+2<r:
    m=(r-l)//2+l
    t=m*B
    c=0
    for i in h:
        if i>t:
            c+=-((-i+t)//k)
        else:
            break
    if c>m:
        l=m
    else:
        r=m+1
print(r-1)

Solution (Python):

if False:
    N=int(input())
    E=[int(i) for i in input().split()]
    E.sort()
    s=sum(E)
    if E[-1]<s-E[-1]:
        print('Yes')
    else:
        print('No')

if False:
    N=int(input())
    fac=[]
    for i in range(1,10**6+1000):
        if N%i==0:
            fac.append((i,N//i))
    ans=10**19
    for l,r in fac:
        ans=min(l-1+r-1,ans)
    print(ans)
  

if False:
    N=int(input())
    S=[input() for _ in range(N)]
    march=list('MARCH')
    nam=[[] for _ in range(len(march))]
    for s in S:
        if s[0] in march:
            nam[march.index(s[0])].append(s)
    ans=0
    for i in range(5):
        for j in range(i+1,5):
            for k in range(j+1,5):
                ans+=len(nam[i])*len(nam[j])*len(nam[k])
    print(ans)


if False:
    import sys

    if sys.getrecursionlimit()<10**7:
        sys.setrecursionlimit(10**7)

    N=int(input())
    ver=[[] for _ in range(N)]
    for _ in range(N-1):
        u,v,W=map(int,input().split())
        ver[u-1].append((v-1,W))
        ver[v-1].append((u-1,W))
    his=[-1 for _ in range(N)]

    def dfs(i,col):
        his[i]=col
        for j,w in ver[i]:
            if his[j]==-1:
                if w%2==0:
                    dfs(j,col)
                else:
                    dfs(j,(col+1)%2)

    dfs(0,0)            
    for i in range(N):
        print(his[i])


N,A,B=map(int,input().split())
H=[int(input()) for _ in range(N)]

def ceil(a,b):
    return (a+b-1)//b

def eno(T):
    nee=0
    td=B*T
    dd=A-B
    for h in H:
        if h-td>0:
            nee+=ceil(h-td,dd)
    return nee<=T

l,r=0,10**9+7
while l+1<r:
    mid=(l+r)//2
    if eno(mid):
        r=mid
    else:
        l=mid
print(r)

Solution (Python):

def main():
    import math
    N, A, B = map(int, input().split())
    h = [int(input()) for i in range(N)]
    d = A - B

    l = 1
    r = max(h)
    while(l+1 < r):
        m = (l+r)//2
        t = m*B
        count = 0
        for x in h:
            if x > t:
                count += math.ceil((x-t)/d)
        if count <= m:
            r = m
        else:
            l = m

    print(r)


main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.buffer.readline
    N, A, B = (int(i) for i in input().split())
    H = [int(input()) for i in range(N)]

    def is_ok(x):
        need = 0
        cur = [0]*N
        for i, h in enumerate(H):
            cur.append(max(0, h - B*x))
        for i, less in enumerate(cur):
            need += (less+(A-B)-1)//(A-B)
        if need <= x:
            return True
        else:
            return False

    def binary_search_meguru():
        ng = -1
        ok = 10**9 + 1
        while abs(ok - ng) > 1:
            mid = ng + (ok - ng) // 2
            if is_ok(mid):
                ok = mid
            else:
                ng = mid
        return ok

    print(binary_search_meguru())


if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.buffer.readline

N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]

ok = 10**18
ng = 0

def isOk(n):
    cnt = 0
    for h in H:
        h -= B * n
        if h > 0:
            cnt += -(-h // (A - B))
    return cnt <= n

while ok - ng > 1:
    mid = (ok + ng) // 2
    if isOk(mid):
        ok = mid
    else:
        ng = mid

print(ok)

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

n, a, b = MAP()
h = [INT() for _ in range(n)]
ad = a - b
l = 1
r = 10 ** 9
while r - l > 1:
    c = (r + l) // 2
    cnt = 0
    for i in range(n):
        cnt += (max(h[i] - b * c, 0) + ad - 1) // ad
    if c > cnt:
        r = c
    else:
        l = c
ans = inf
for i in range(l, r + 1):
    cnt = 0
    for j in range(n):
        cnt += (max(h[j] - b * i, 0) + ad - 1) // ad
    ans = min(ans, max(i, cnt))
print(ans)

Solution (Python):
N,A,B = map(int, input().split())
H = [int(input()) for i in range(N)]

def check(X):
    """ X回以下の爆発で全滅するか """
    ans = 0
    for h in H:
        cnt = ((h - B * X) + (A - B) - 1) // (A - B)
        ans += max(0, cnt)
    return ans <= X

def main():
    ng = 0
    ok = 10 ** 10
    while ok - ng > 1:
        mid = (ok + ng) // 2
        if check(mid):
            ok = mid
        else:
            ng = mid
    print(ok)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]

    under = 0
    r = (max(H) + B - 1) // B
    c = A - B
    while r - under > 1:
        m = (r + under) // 2
        rem = 0
        for hi in H:
            hi -= B*m
            if hi <= 0: continue
            rem += (hi + c - 1) // c
        if rem <= m: r = m
        else: under = m
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    low = 0; high = 10 ** 20
    while high - low > 1:
        mid = (low + high) // 2
        explosion = B * mid
        direct = 0
        for h in H:
            if h - explosion > 0:
                direct += (h - explosion) // (A - B)
                if (h - explosion) % (A - B) > 0: direct += 1
        if direct <= mid: high = mid
        else: low = mid
    print(high)

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
n, a, b = map(int, input().split())
H = [int(input()) for i in range(n)]

def ok(x):
    t = 0
    for i in range(n):
        h = H[i]
        res = h-b*x
        if res <= 0:
            continue
        else:
            if res%(a-b) == 0:
                t += res//(a-b)
            else:
                t += res//(a-b)+1
    if t <= x:
        return True
    else:
        return False

l = 0
r = 10**10
while l+1 < r:
    c = (l+r)//2
    if ok(c):
        r = c
    else:
        l = c
print(r)

Solution (Python):
N,A,B = map(int,input().split())
H = [int(input()) for i in range(N)]

def is_ok(k):
    hp = []
    for h in H:
        if h - B*k > 0:
            hp.append(h - B*k)
    if len(hp)==0: return True
    x = 0
    for h in hp:
        x += 0--h//(A-B)
        if x > k: return False
    return True

ok = 10**14
ng = 0
while ok-ng > 1:
    m = (ok+ng)//2
    if is_ok(m):
        ok = m
    else:
        ng = m
print(ok)

Solution (Python):
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]

l = 0
r = max(h) // b + 1
while r - l > 1:
    m = (l + r) // 2
    count = 0
    for x in h:
        x = x - m * b
        if x > 0:
            count += (x + a - b - 1) // (a - b)
    if count <= m:
        r = m
    else:
        l = m
print(r)

Solution (Python):
N, A, B , *h = map(int, open(0).read().split())
C = A-B
l = -1
r = 10**12
while l+1<r:
  s = (l+r)//2
  cnt = sum((c-s*B+C-1)//C if c-s*B>0 else 0 for c in h)
  if cnt>s:
    l = s
  else:
    r = s
print(r)

Solution (Python):
N, A, B , *h = map(int, open(0).read().split())
C = A-B
l = -1
r = 10**20
while l+1<r:
  s = (l+r)//2
  M = [c-s*B for c in h]
  cnt = sum((c+C-1)//C if c>0 else 0 for c in M)
  if cnt>s:
    l = s
  else:
    r = s
print(r)

Solution (Python):
from collections import *
from itertools import *
from bisect import *
from heapq import *

import math
from fractions import gcd
import sys


import copy

N,A,B=map(int,input().split())
H=[int(input()) for i in range(N)]
H.sort()
ng=0
ok=10**18
A-=B
while ok-ng>1:

    mid=(ok+ng)//2
    c=bisect_right(H,mid*B)

    _sum=0
    for i in range(c,N):
        Z=H[i]-mid*B
        _sum+=Z//A+bool(Z%A)
    
    if mid>=_sum:
        ok=mid
    else:
        ng=mid
print(ok)

Solution (Python):
import numpy as np

n, a, b = map(int, input().split())
h = np.array([int(input()) for _ in range(n)], dtype=np.int64)


def f(x):
    li = h - b * x
    li[li < 0] = 0
    cnt = np.ceil(li / (a - b))
    ret = cnt.sum() <= x
    return ret


l = 0
r = np.ceil(max(h) / b).astype(np.int64)
while r - l > 1:
    mid = (l + r) // 2
    if f(mid):
        r = mid
    else:
        l = mid

print(r)