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())
ls = [int(input()) for _ in range(n)]
m = max(ls)
lo = (m + a - 1) // a
hi = (m + b - 1) // b + 1
mi = (hi + lo) // 2
while hi > lo + 1:
    mi = (hi + lo) // 2
    if sum([(max(x - mi * b, 0) + a - b - 1) // (a - b) for x in ls]) <= mi:
        hi = mi
    else:
        lo = mi
if sum([(max(x - lo * b, 0) + a - b - 1) // (a - b) for x in ls]) <= lo:
    print(lo)
else:
    print(hi)

Solution (Python):
n, a, b = map(int, input().split())
ls = sorted([int(input()) for _ in range(n)])
lo = (ls[-1] + a - 1) // a
hi = (ls[-1] + b - 1) // b + 1
mi = (hi + lo) // 2
while hi > lo + 1:
    mi = (hi + lo) // 2
    if sum([(max(x - mi * b, 0) + a - b - 1) // (a - b) for x in ls]) <= mi:
        hi = mi
    else:
        lo = mi
if sum([(max(x - lo * b, 0) + a - b - 1) // (a - b) for x in ls]) <= lo:
    print(lo)
else:
    print(hi)

Solution (Python):
import math
monsterNum, centerDamage, otherDamage = map(int, input().split())
monsterHitpoint = [0] * monsterNum
maxHitpoint = 0

def enough(times):
  result = True
  damageCount = 0
  hitpoint = [monsterHitpoint[i] - otherDamage * times for i in range(monsterNum)]
  for i in range(monsterNum):
    if hitpoint[i] > 0:
      damageCount += math.ceil(hitpoint[i] / (centerDamage - otherDamage))
    if damageCount > times:
      result = False
      break
  return result
  
for i in range(monsterNum):
  monsterHitpoint[i] = int(input())
  if maxHitpoint < monsterHitpoint[i]:
    maxHitpoint = monsterHitpoint[i]

low, high = 0, math.ceil(maxHitpoint / otherDamage)
while low <= high:
  minTimes = (low + high) // 2
  checkEnough = enough(minTimes)
  if checkEnough and not(enough(minTimes - 1)):
    break
  elif checkEnough:
    high = minTimes - 1
  elif not checkEnough and (enough(minTimes + 1)):
    minTimes += 1
    break
  elif not checkEnough:
    low = minTimes + 1
print(minTimes)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce



sys.setrecursionlimit(2147483647)
INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, a, b = LI()
L = IR(n)
ok = max(L) // b + 1
ng = 0
while ok > ng + 1:
    mid = (ok + ng) // 2
    remain = mid
    for i in range(n):
        remain -= max(0, (L[i] - b * mid) // (a - b) + bool((L[i] - b * mid) % (a - b)))
        if remain < 0:
            ng = mid
            break
    else:
        ok = mid



print(ok)

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

sum_h = sum(h)
sum_dam = B * N + (A - B)
ng = (sum_h - 1) // sum_dam + 1 - 1
ok = (max(h) - 1) // B + 1
ans = (ng + ok + 1) // 2
while ok - ng > 1:
    cnt = ans
    flag = 0
    for h_i in h:
        rem = h_i - B * ans
        if rem > 0:
            cnt -= (rem - 1) // (A - B) + 1
            if cnt < 0:
                flag = 1
                break
    if flag == 0:
        ok = ans
    else:
        ng = ans
    ans = (ng + ok + 1) // 2

print(ans)

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

H = [int(input()) for _ in range(N)]


H.sort(reverse=True)
high = math.ceil(H[0] / B)
low = 0
while high > low+1:
    mid = (high+low) // 2
    cnt = 0
    for i in range(N):
        if H[i] - mid*B > 0:
            
            cnt += math.ceil((H[i] - mid*B)/(A - B))
        else:
            break
    
    if cnt <= mid:
        high = mid
    else:
        low = mid

print(high)

Solution (Python):
from bisect import bisect

def solve(N, A, B, H, total, M):
    class Solver:
        def __init__(self, N, A, B, H, total):
            self.N = N
            self.B = B
            self.BA = A-B
            self.H = H
            self.len = idiv(total, B)

        def __getitem__(self, k):
            Bk = self.B * k
            cnt = 0
            for i in range(self.N):
                h = H[i] - Bk
                if h < 0:
                    continue
                cnt += idiv(h, self.BA)
                if cnt > k:
                    return -1
            
            return 1 if cnt <= k else -1

        def __len__(self):
            return self.len

    k0 = idiv(total, (B*N+A))
    s = Solver(N, A, B, H, total)
    k = bisect(s, 0, k0, idiv(M, B))
    print(k)

def main():
    input = open(0).readline
    N, A, B = map(int, input().split())
    H = [0]*N
    M = 0
    total = 0
    for i in range(N):
        h = int(input())
        H[i] = h
        M = max(M, h)
        total += h
    solve(N, A, B, H, total, M)

def idiv(x, y):
    if x <= 0:
        return 0
    q, r = divmod(x, y)
    return q + (1 if r > 0 else 0)



main()

Solution (Python):
from bisect import bisect

def solve(N, A, B, H, total):
    class Solver:
        def __init__(self, N, A, B, H, total):
            self.N = N
            self.B = B
            self.BA = A-B
            self.H = H
            self.len = idiv(total, B)

        def __getitem__(self, k):
            Bk = self.B * k
            cnt = 0
            for i in range(self.N):
                h = H[i] - Bk
                if h < 0:
                    continue
                cnt += idiv(h, self.BA)
                if cnt > k:
                    return -1
            
            return 1 if cnt <= k else -1

        def __len__(self):
            return self.len

    k0 = idiv(total, (B*N+A))
    s = Solver(N, A, B, H, total)
    k = bisect(s, 0, k0)
    print(k)

def main():
    input = open(0).readline
    N, A, B = map(int, input().split())
    H = [0]*N
    total = 0
    for i in range(N):
        h = int(input())
        H[i] = h
        total += h
    solve(N, A, B, H, total)

def idiv(x, y):
    if x <= 0:
        return 0
    q, r = divmod(x, y)
    return q + (1 if r > 0 else 0)



main()

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

def can_defeat(n):
    global mons
    global a
    global b
    base = b*n
    sup = 0
    for m in mons:
        if m-base > 0:
            sup += (m-base)//(a-b)+min((m-base)%(a-b),1)
    if sup <= n:
        return True
    else:
        return False

def bin_search(eval_func,left,right):
    if right-left <= 2:
        for i in range(left,right+1):
            if eval_func(i):
                return i
    mid = (left+right)//2
    if eval_func(mid):
        return bin_search(eval_func,left,mid)
    elif eval_func(right):
        return bin_search(eval_func,mid,right)

print(bin_search(can_defeat,0,int(1e10)))

Solution (Python):
def main():

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

    l, r = 0, max(H) // B + 1
    while l < r:
        m = (l + r) // 2
        if isvalid(m, H, N, A, B):
            r = m
        else:
            l = m + 1

    return r

def isvalid(n, H, N, A, B):
    alive = []
    for i in range(len(H)):
        if H[i] - n*B > 0:
            alive.append(H[i]-n*B)
    count = 0
    for v in alive:
        if v % (A-B) == 0:
            count += v //(A-B)
        else:
            count += v //(A-B) + 1
    if count <= n:
        return True
    else:
        return False



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

Solution (Python):
import sys,bisect as bs,collections as cl,heapq as hq
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

n,a,b = m()

h = []

for i in range(n):
    h.append(onem())

h.sort(reverse = True)

l = 1
r = h[0]//b+1

while l != r:
    x = (l+r)//2
    ct = 0
    for i in range(n):
        ct += ((a-b-1) + max(0,h[i]-b*x))//(a-b)
    if ct > x:
        l = x+1
    else:
        r = x
print(l)

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

def main():
    N, A, B = map(int, input().split())
    h = sorted([int(input()) for i in range(N)], reverse=True)

    MAX = (h[0] // B) + 1

    l, r = 0, MAX
    while True:
        
        if l + 1 >= r:
            print(r)
            break
        t = (l + r) // 2
        Bt = B * t
        a = 0
        i = 0
        while i < N and h[i] > Bt:
            tmp = h[i] - Bt
            if tmp % (A-B) == 0:
                a += tmp // (A-B)
            else:
                a += tmp // (A-B) + 1
            i += 1
        
        if a <= t:
            l, r = l, t
        else:
            l, r = t, r

if __name__ == "__main__":
    main()

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

le = 0
ri = max(H) // b + 2
mid = (le + ri) // 2
while ri - le > 1:
    ad_n = 0
    for i in range(n):
        hh = max(0, H[i] - mid * b)
        
        ad_n += -(-hh // ad)
    
    if ad_n > mid:  
        le = mid
    else:
        ri = mid
    mid = (le + ri) // 2
print(le+1)

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

def judge(k):
    _sum = 0
    for hh in h:
        t = hh-k*b
        if t > 0:
            _sum += (t+a-b-1) // (a-b)
            if _sum > k:
                return False;
    return True


high, low = int(1e9+9), 0

while low < high:
    mid = int((high + low) / 2)
    if judge(mid):
        high = mid;
    else:
        low = mid+1;

print(low)

Solution (Python):
n, a, b = map(int, input().split())
h = [int(input()) for _ in range(n)]
l = 0
r = 10 ** 10
c = a - b
while l + 1 != r:
    m = (l + r) // 2
    tmp = 0
    for i in range(n):
        if h[i] > b * m:
            tmp += ((h[i] - b * m) // c + (1 if (h[i] - b * m) % c else 0))
    if tmp > m:
        l = m
    else:
        r = m
print(r)

Solution (Python):
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
l=1;r=max(h)//b+1
while l!=r:
  x=(l+r)//2
  ct=0
  for i in range(n):
    ct+=((a-b-1)+max(0,h[i]-b*x))//(a-b)
  if ct>x:
    l=x+1
  else:
    r=x
print(l)

Solution (Python):
n,a,b=map(int,input().split())
h=[int(input()) for i in range(n)]
l=1;r=max(h)//b+1
while l!=r:
  x=(l+r)//2
  ct=0
  for i in range(n):
    ct+=((a-b-1)+max(0,h[i]-b*x))//(a-b)
  if ct>x:
    l=x+1
  else:
    r=x
print(l)

Solution (Python):

import sys
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import math
sys.setrecursionlimit(12345678)


def can_delete(ml, t, a, b):
    for i in range(len(ml)):
        ml[i] -= (b * t)

    count = 0
    for m in ml:
        if m > 0:
            count += math.ceil(m/(a-b))

    return t >= count


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

    l = 0
    r = 10**9
    while l < r:
        m = (l + r) // 2
        if can_delete(monsters[:], m, a, b):
            r = m
        else:
            l = m + 1

    print(r)


if __name__ == '__main__':
    main()

Solution (Python):

import sys
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop
import math
sys.setrecursionlimit(12345678)


def can_delete(ml, t, a, b):
    for i in range(len(ml)):
        ml[i] -= (b * t)

    count = 0
    for m in ml:
        if m > 0:
            count += math.ceil(m/(a-b))

    return t >= count


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

    l = 0
    r = 10**9
    while l < r:
        m = (l + r) // 2
        if can_delete(monsters.copy(), m, a, b):
            r = m
        else:
            l = m + 1

    print(r)


if __name__ == '__main__':
    main()

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

def func(l,r):
    if l == r:
        return l
    c = (l+r)//2
    hoge = 0
    for i in h:
        hoge += max(math.ceil((i-(B*c))/(A-B)),0)
    if hoge > c:
        return func(c+1,r)
    elif hoge < c:
        return func(l,c)
    else:
        return c

print(func(0,10**9+7))

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def f(t):
    lst = list(map(lambda x: max(0, math.ceil((x-b*t)/(a-b))),h))
    if sum(lst) <= t:
        return True
    return False

n,a,b = LI()
h = [I() for _ in range(n)]
maxh = max(h)
ok,ng = math.ceil(maxh/b),0
while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if f(mid):
        ok = mid
    else:
        ng = mid
print(ok)

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

sorted_H = sorted(H, reverse=True)

def is_enough(num):
    cnt = 0
    for x in range(N):
        if sorted_H[x] - num * B > 0:
            cnt += (sorted_H[x] - num * B) // (A - B)
            if (sorted_H[x] - num * B) % (A - B) != 0:
                cnt += 1
        else:
            break
    return cnt <= num

limit = (sorted_H[0] // B) + 1

i = 0
j = limit
while True:
    k = (j + i) // 2
    if is_enough(k):
        if i + 1 == k:
            print(k)
            break
        j = k
    else:
        if k + 1 == j:
            print(k + 1)
            break
        i = k

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

def check(m):
    tmp=0
    for i in range(n):
        if (h[i]-b*m)/(a-b)>0:
            tmp+=math.ceil((h[i]-b*m)/(a-b))
    if tmp<=m:
        return True
    else:
        return False

low=0
high=max(h)
while high-low>1:
    mid=(low+high)//2
    if check(mid):
        high=mid
    else:
        low=mid
    
    
print(high)

Solution (Python):
n,a,b=map(int,input().split())
t=a-b

ans=[0]*2

d=[]
for i in range(n):
    h=int(input())
    d.append(h)
d.sort(reverse=True)
ans[1]=max(d)
while ans[1]-ans[0]!=1:
    x=z=(ans[1]+ans[0])//2
    y=x*b
    for i in range(n):
        p=d[i]-y
        if p<=0:
            break
        x-=(p+t-1)//t
        if x<0:
            break
    if x<0:
        ans[0]=z
    else:
        ans[1]=z
print(ans[1])

Solution (Python):
from bisect import bisect_left
try:
    from collections.abc import Sequence
except:
    from collections import Sequence


class LazySequence(Sequence):
    def __init__(self, f, n):
        self.f = f
        if isinstance(n, int):
            self.r = range(n)
        elif isinstance(n, range):
            self.r = n
        else:
            raise TypeError

    def __len__(self):
        return len(self.r)

    def __getitem__(self, i):
        r = self.r[i]
        if isinstance(r, int):
            return self.f(r)
        else:
            return self.__class__(self.f, r)


N, A, B = map(int, input().split())
D = A - B
H = [int(input()) for _ in range(N)]
H.sort()
l = (H[0] - 1) // A + 1
r = (H[-1] - 1) // B + 1


def isenough(n):
    b = B * n
    for h in H:
        n -= max(0, (h - b - 1) // D + 1)
        if n < 0:
            return False
    return True


a = LazySequence(isenough, r + 1)
ans = bisect_left(a, True, l, r)
print(ans)

Solution (Python):
from bisect import bisect_left
try:
    from collections.abc import Sequence
except:
    from collections import Sequence


class LazySequence(Sequence):
    def __init__(self, f, n):
        self.f = f
        if isinstance(n, int):
            self.r = range(n)
        elif isinstance(n, range):
            self.r = n
        else:
            raise TypeError

    def __len__(self):
        return len(self.r)

    def __getitem__(self, i):
        r = self.r[i]
        if isinstance(r, int):
            return self.f(r)
        else:
            return self.__class__(self.f, r)


N, A, B = map(int, input().split())
D = A - B
H = [int(input()) for _ in range(N)]
H.sort()
l = (H[0] - 1) // A + 1
r = (H[-1] - 1) // B + 1


def isenough(n):
    b = B * n
    for h in H:
        n -= max(0, (h - b - 1) // D + 1)
        if n < 0:
            return False
    return True


a = LazySequence(isenough, r + 1)
ans = bisect_left(a, True, l, r)
print(ans)

Solution (Python):
def calc(n):
    damage = (b * n)
    d = [max(dd - damage, 0) for dd in h]
    a_num = 0
    for i in range(len(d)):
        a_num += max(0, 1 + (d[i]-1) // (a - b))
    if a_num <= n:
        return True
    return False

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

left = 0
right = 10000000000

while (right - left) > 1:
    middle = (left + right) // 2
    if calc(middle):
        right = middle
    else:
        left = middle
print(right)

Solution (Python):
n,a,b=[int(j) for j in input().split()]
s=a-b
h=[]
for i in range(n):
    p=int(input())
    h.append(p)
h.sort()
import bisect
import math
def f(m):
    n=bisect.bisect_right(h,m*b)
    l=h[n:]
    c=0
    for i in range(len(l)):
        if l[i]-m*b/s>0:
            c+=math.ceil((l[i]-m*b)/s)
    if c<=m:
        return True
    else:
        return False
        


left=0
right=10**15
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid   
    else:
        left=mid
print(right)

Solution (Python):
n,a,b=[int(j) for j in input().split()]
s=a-b
h=[]
for i in range(n):
    p=int(input())
    h.append(p)
h.sort()
import bisect
import math
def f(m):
    n=bisect.bisect_right(h,m*b)
    l=h[n:]
    c=0
    for i in range(len(l)):
        if l[i]-m*b/s>0:
            c+=math.ceil((l[i]-m*b)/s)
    if c<=m:
        return True
    else:
        return False
        


left=0
right=10**15
while right-left>1:
    mid=(left+right)//2
    if f(mid):
        right=mid   
    else:
        left=mid
print(right)

Solution (Python):
_,a,b,*H=map(int,open(0).read().split())
l,r=0,10**9
while r-l>1:
	m=(l+r)//2
	if-sum(min(0,(h-m*b)//(b-a))for h in H)>m:l=m
	else:r=m
print(r)

Solution (Python):
n,a,b,*H=map(int,open(0).read().split())
l,r=0,10**9
while r-l>1:
	x=0;m=(l+r)//2
	for h in H:
		x-=min(0,(h-m*b)//(b-a))
	if x>m:
		l=m
	else:
		r=m
print(r)

Solution (Python):
n,a,b,*H=map(int,open(0).read().split())
l,r=0,10**9
while r-l>1:
	x=0
	m=(l+r)//2
	s=m*b
	for h in H:
		x-=min(0,(h-s)//-(a-b))
	if x>m:
		l=m
	else:
		r=m
print(r)

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

def check(m):
    m2 = m
    for i in range(n):
        if h[i] <= b * m:
            continue
        m2 -= math.ceil((h[i] - b * m) / (a - b))
        if m2 < 0:
            return False
    return True

l, r = 0, sum(h)//b+1
while r - l > 1:
    mid = (r + l) // 2
    
    if check(mid):
        r = mid
    else:
        l = mid

print(r)

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')


def A():
    a, b = LI()
    if a + b >= 10:
        print("error")
    else:
        print(a + b)
    return


def B():
    s = S()
    if len(s) == len(set(s)):
        print("yes")
    else:
        print("no")
    return


def C():
    n = II()
    m = inf
    ans = 0
    for _ in range(n):
        s = II()
        ans += s
        if s % 10:
            m = min(m, s)
    if ans % 10:
        print(ans)
    else:
        if m != inf:
            print(ans - m)
        else:
            print(0)
    return






def D():
    def f(t):
        lh = list(map(lambda x: max(0, (x - b * t - 1) // (a - b) + 1), h))
        if sum(lh) <= t:
            return True
        return False
    n, a, b = LI()
    h = IR(n)
    maxh = max(h)
    ok = (maxh - 1) // b + 1
    ng = 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if f(mid):
            ok = mid
        else:
            ng = mid
    print(ok)
    return



if __name__ == '__main__':
    D()

Solution (Python):
N, A, B = map(int, input().split())
hs = []
for i in range(N):
  h = int(input())
  hs.append(h)
def check(n):
  s = 0
  for h in hs:
    if h > B*n:
      s += (h-B*n +A-B-1)//(A-B)
  return s <= n
a = 0
b = max(hs)//B+1
while a < b:
  i = (a + b)//2
  if check(i):
    b = i
  else:
    if a == i:
      break
    a = i
r = b
print(r)

Solution (Python):

import bisect
import collections
import itertools


def getint(): return int(input())
def getints(): return list(map(int, input().split()))
def getint2d(rows): return [getints() for _ in range(rows)]
def getgrid(rows): return [input() for _ in range(rows)]
def array1d(n, value): return [value for _ in range(n)]
def array2d(n, m, value): return [array1d(m, value) for _ in range(n)]

n,a,b=getints()
hs=[getint() for _ in range(n)]
mx=max(hs)

min_cast = 0
max_cast = mx+1
c = a-b

hs = list(sorted(hs,reverse=True))

while min_cast < max_cast:
    cast = (min_cast + max_cast) // 2
    
    
    need = 0
    dec = b * cast
    for v in hs:
        v = v - dec
        if v <= 0:
            break
        need += (v + c - 1) // c
    if need <= cast:
        max_cast = cast
    else:
        min_cast = cast + 1

print(min_cast)

Solution (Python):

import sys
import math
INF = float("inf")


def solve(N: int, A: int, B: int, h: "List[int]"):
    tot = sum(h)

    def isOK(index):
        base = B*index
        sub = A-B
        counter = 0
        for hh in h:
            if hh > base:
                counter += int(math.ceil((hh-base)/sub))
            if index < counter:
                return False

        return index >= counter

    ng = -1
    ok = 2*tot//(N*B) + 1
    

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


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = int(next(tokens))  
    B = int(next(tokens))  
    h = [int(next(tokens)) for _ in range(N)]  
    solve(N, A, B, h)


if __name__ == '__main__':
    main()

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

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

def judge(m) :
    s = 0
    for i in range(N) :
        t = max(0, (h[i]-m*B+A-B-1)//(A-B))
        s += t
        if s > m :
            return False
    return True    

h.sort(reverse=True)
l, r = -1, 10 ** 9 + 1
while r - l > 1 :
    m = (l + r) // 2
    if judge(m) :
        r = m
    else :
        l = m

print(r)

Solution (Python):
import math

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

def is_ok(x):
    c = 0
    for i in range(n):
        t = h[i] - b * x
        if t <= 0:
            continue
        c += math.ceil(t / (a - b))
    return c <= x

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

print(ok)

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

for _ in range(N):
    HP.append(int(input()))

left = 0
right = max(HP)

def canKill(count):
    ness = 0
    for hp in HP:
        ness += max(-(-(hp - B * count) // (A - B)), 0)
    if ness <= count:
        return True
    return False

while right - left > 1:
    middle = left + (right - left) // 2
    if canKill(middle):
        right = middle
    else:
        left = middle

print(right)

Solution (Python):
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right

import re







def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 


def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]



def check(h, x, A, B):
    h = [ hi - B * x for hi in h ]
    c = 0
    for hi in h:
        if hi <= 0:
            continue
        c += math.ceil(hi/(A-B))
    return c <= x

def main():
    N, A, B = l_inpl()
    h = line_inpl(N)

    l, r = 0, max(h)//B + 1000
    while l + 1 != r:
        mid = (l+r) // 2
        if check(h, mid, A, B):
            r = mid
        else:
            l = mid
    
    print(r)

if __name__ == "__main__":
    main()

Solution (Python):
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
c=a-b
h_list=[int(input()) for i in range(n)]
l=1
r=(max(h_list)+b-1)//b
while r-l>1:
    m=(l+r)//2
    count=0
    for i in h_list:
        if i<=b*m:
            pass
        else:
            count+=((i-b*m)+c-1)//c
    if count<=m:
        r=m
    else:
        l=m
print(r)

Solution (Python):
import sys
input=sys.stdin.readline
n,a,b=map(int,input().split())
c=a-b
h_list=[int(input()) for i in range(n)]
l=0
r=(max(h_list)+b-1)//b
while r-l>1:
    m=(l+r)//2
    count=0
    for i in h_list:
        if i<=b*m:
            pass
        else:
            count+=((i-b*m)+c-1)//c
    if count<=m:
        r=m
    else:
        l=m
print(r)

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

def b_search(a,b,value,lim):
    med=(a+b)//2
    if a==b:return a
    elif lim=="upper":
        if a+1==b:
            if value(b):return b
            else:return a
        elif value(med):return b_search(med,b,value,lim)
        else:return b_search(a,med-1,value,lim)
    else:
        if a+1==b:
            if value(a):return a
            else:return b
        elif value(med):return b_search(a,med,value,lim)
        else:return b_search(med+1,b,value,lim)
        
def value(x):
    return sum([max(ceil((i-x*b)/c),0) for i in h])<=x
    
print(b_search(1,10**9,value,"lower"))

Solution (Python):
def cond(arr,m):
  tmp=0
  for i in range(n):
    if m*b>=arr[i]:
      continue
    else:
      tmp+=(arr[i]-m*b+(a-b-1))//(a-b)
  if tmp<=m:
    return True
  else:
    return False

def bisect(l,r):
    while r-l!=1:
        m=(r+l)//2
        if cond(arr,m)==True:
            r=m
        else:
            l=m
    return r

n,a,b=map(int,input().split())
arr=[int(input()) for _ in range(n)]
print(bisect(-1,10**9+1))

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

def binary_search(l,r,func):
    if func(l):return l-1
    if not func(r):return r
    while l+1<r:
        i = (l+r)//2
        if func(i):
            r = i
        else:
            l = i
    return l

def f(K):
    c = sum(max(0,(h-B*K-1)//(A-B)+1) for h in H)
    return c<=K

print(binary_search(0,10**9,f)+1)

Solution (Python):
n,a,b=map(int,input().split())
arr=[int(input()) for _ in range(n)]
l=0
r=10**9+1
while r-l!=1:
  tmp=0
  m=(l+r)//2
  for i in range(n):
    if m*b>=arr[i]:
      continue
    else:
      tmp+=(arr[i]-m*b+(a-b-1))//(a-b)
  if tmp<=m:
    r=m
  else:
    l=m
print(r)

Solution (Python):
N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]
lb, ub = 0, 10**9
while ub > lb + 1:
    mid = (lb + ub) // 2
    t, C, cnt = mid * B, A - B, 0
    for h in H:
        if h > t:
            tmp = h - t
            cnt += tmp // C + (tmp % C != 0)
            if cnt > mid:
                break
    if mid < cnt:
        lb = mid
    else:
        ub = mid
print(ub)