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



Sample input:
4 5 3
8
7
4
2


Sample output:
2

Submission status: Accepted

Solution code:
from numpy import*
t,*h=open(0)
_,a,b=int32(t.split())
i,j=0,2**30
while~i+j:
 k=(j+i)//2;t=(b*k-int32(h))//(a-b)
 if-k>sum(t[t<0]):i=k
 else:j=k
print(j)

Submission status: Accepted

Solution code:
n,a,b,*h=map(int,open(0).read().split())
i,j=0,2**30
while~i+j:
 k=c=(j+i)//2
 for t in h:c+=min(0,(b*k-t)//(a-b))
 if c<0:i=k
 else:j=k
print(j)

Submission status: Accepted

Solution code:
from numpy import*
from copy import deepcopy

def main():
    n,a,b,*h=map(int,open(0).read().split())
    h=array(h)
 
    ok=-1
    ng=max(h)+10
    
    def judge(t):
        H=deepcopy(h)
        H-=b*t
        H=H[H>0]
        if sum((H-1)//(a-b)+1)<=t:
            return 1
        else:
            return 0
    
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
        if judge(mid):
            ng=mid
        else:
            ok=mid
    l=ok+1
    print(l)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#import numpy as np
from numpy import*
#from scipy.sparse.csgraph import shortest_path #shortest_path(csgraph=graph)
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse import csr_matrix

from collections import* #defaultdict Counter deque appendleft
from fractions import gcd
from functools import* #reduce
from itertools import* #permutations("AB",repeat=2) combinations("AB",2) product("AB",2) groupby accumulate
from operator import mul,itemgetter
from bisect import* #bisect_left bisect_right
from heapq import* #heapify heappop heappushpop
from math import factorial,pi
from copy import deepcopy
import sys
sys.setrecursionlimit(10**8)
#input=sys.stdin.readline  #危険！基本オフにしろ！

def main():
    n,a,b,*h=map(int,open(0).read().split())
    h=array(h)

    ok=-1
    ng=max(h)+10
    
    def judge(t):
        H=deepcopy(h)
        H-=b*t
        H=H[H>0]
        if sum((H-1)//(a-b)+1)<=t:
            return 1
        else:
            return 0
    
    while abs(ok-ng)>1:
        mid=(ok+ng)//2
#        print(mid,"NY"[judge(mid)])
        if judge(mid):
            ng=mid
        else:
            ok=mid
    l=ok+1
    print(l)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
a-=b
h=[]
s=0
for i in range(n):
    x=int(input())
    h.append(x)
    s+=x
h.sort(reverse=True)
x,z,f=0,2**(len(bin((s+b-1)//b))-2),0
while x!=z:
    if z-x==1:f=1
    y=(x+z)//2
    j=0
    for k in h:
        if k<y*b:break
        j+=(k-y*b+a-1)//a
    if f==0:
        if j>y:x=y
        else:z=y
    if f==1:
        if j>y:print(z)
        else:print(x)  
        break

Submission status: Accepted

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    from heapq import heappop, heappush, heappushpop
    from math import floor,ceil,sqrt,factorial
    """O(max(h)*log(n))なので無理
    N, A, B = MI()
    H = []
    #heapで最大を持ち続けたいのでマイナスにして格納するよ!(popするときは符号反転させる)
    for _ in range(N):
        h=I()
        heappush(H, -h)
    C = A - B
    
    for i in range(1, -H[0] // B + 2):
        heappushpop(H, H[0] + C)
        print(H[0],i,i*B)
        if - H[0] <= i * B:
            print(i)
            break
            """
    #操作回数で二分探索
    N, A, B = MI()
    H = LIN(N)
    C=A-B

    def is_ok(n):
        cnt = 0
        for h in H:
            cnt+=max(0,ceil((h-n*B)/C))
        return cnt <= n
        
    ok = 10 ** 9 // B + 1
    ng=0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if is_ok(mid):
            ok = mid
        else:
            ng = mid
    print(ok)

        
        
        

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def can_eliminate(n): #O(N)
  H_ = [((h-B*n)+A-B-1)//(A-B) for h in H if h>B*n]
  if sum(H_)<=n:
    #print('can eliminate by ' + str(n) +'times')
    return True
  else:
    #print('can not eliminate by ' + str(n) +'times')
    return False
    
def binary_search(l,r): #r:inclusive
  #print('search between ' + str((l,r)))
  if r==l+1:
    if can_eliminate(l):
      return l
    else:
      return r
  
  c = (l+r)//2
  if can_eliminate(c):
    return binary_search(l,c)
  else:
    return binary_search(c,r)
  
print(binary_search(1, (sum(H)+2*B+1)//B))

Submission status: Accepted

Solution code:
def enough(T, N, A, B, H):
	d = A - B
	cnt = 0
	for i in H:
		cnt += max(0, (i - T * B - 1)//d + 1)
	if cnt <= T:
		return 1
	else:
		return 0


N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
M = (max(H) - 1)//B + 1
hi_z, hi_p = M, 1
low_z, low_p = 0, 0
t = M
while hi_z - low_z > 1:
	mid_z = (hi_z + low_z)//2
	mid_p = enough(mid_z, N, A, B, H)
	if mid_p == 1:
		hi_z, hi_p = mid_z, mid_p
	else:
		low_z, low_p = mid_z, mid_p
print(hi_z)

Submission status: Accepted

Solution code:
N,A,B = [ int(it) for it in input().split() ]
li = [ int(input()) for i in range(N) ]

def isOK(p):
  lic = sum([ (max(0,it-p*(B))+(A-B-1))//(A-B) for it in li ])
  if lic <= p:
    return True
  else:
    return False

low = 0
high = 10000000000
for i in range(1000000000):
  key = (low+high)//2
  flag = isOK(key)
  if ( flag ):
    high = key
  else:
    low = key
  if ( low + 1 >= high ):
    break
print ( high )

Submission status: Accepted

Solution code:
import numpy as np

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

def test(n):
  # n回の魔法で全滅させられるか
  x = h - n*B
  x[x<0] = 0
  return np.ceil(x/(A-B)).sum() <= n


left = 0 # 倒せない
right = 10**9 # 倒せる

while right - left > 1:
  mid = (left + right)>>1
  if test(mid):
    right = mid
  else:
    left = mid

answer = right
print(answer)

Submission status: Accepted

Solution code:
from math import ceil

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


# 二分法により解を求める
def bis(p, ok, ng):
    mid = (ok + ng) // 2
    return (
        ok if abs(ok - ng) == 1 else
        bis(p, mid, ng) if p(mid) else
        bis(p, ok, mid)
    )


ans = bis(
    lambda k: sum(max(0, ceil((x - k * B) / (A - B))) for x in h) <= k,
    10**10,
    0
)

# 出力
print(ans)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
H=[int(input()) for _ in [0]*N]
l,r=0,10**10
while l+1 < r:
    k=(l+r)//2
    if sum([max(0,(h-B*k-1)//(A-B)+1) for h in H]) > k:l=k
    else:r=k
print(r)

Submission status: Accepted

Solution code:
import sys
import math
input = sys.stdin.readline
N, A, B = map(int, input().split())
h_list = []
for _ in range(N):
    h_list.append(int(input()))

def compare(k):
    cnt = 0
    for h in h_list:
        tmp_h = h - k*B
        x = max(math.ceil(tmp_h/(A-B)),0)
        cnt += x
        if cnt > k:
            return False
    return True
def solve():
    ng = 0
    ok = math.ceil(max(h_list) / B)
    while abs(ok-ng) > 1:
        mid = (ng + ok) // 2
        res = compare(mid)
        if (res):
            ok = mid
        else:
            ng = mid
    return ok
print(solve())

Submission status: Accepted

Solution code:

n,a,b = map(int,input().split())
h=[int(input()) for i in range(n)]
def solve(t):
    cur = 0
    for i in range(n):
        cur +=max(-(-(h[i]-b*t)//(a-b)),0)
    return cur <= t

def binary_search(l,r):
    while abs(r-l) >1:
        mid = (l+r)//2
        if solve(mid):#判定のとこは別で
            r = mid
        else:
            l = mid
    return r
print(binary_search(0,10**9+1))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    x=int(input())
    h.append(x)

def check(t):
    c=0
    for i in range(n):
        c+=1+(max(0,h[i]-b*t)-1)//(a-b)
    return t>=c

l=0
r=3+max(h)//b
while r-l>1:
    mid=(r-l)//2+l
    if check(mid):
        r=mid
    else:
        l=mid
ans=l
if check(r):
    ans=r
print(ans)

Submission status: Accepted

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

h = []
for i in range(n):
    h.append(int(input()))
st,ed = 0,10**9+1
while st<ed-1:
    mid = (st+ed)//2
    #print(mid)
    tmp = 0
    for i in range(n):
        x = h[i]-mid*b
        if x>0:
            tmp+=(x//(a-b))+(x%(a-b)>0)
    if tmp<=mid:
        ed = mid
    else:
        st = mid
print(ed)

Submission status: Accepted

Solution code:
from functools import reduce
import math

def is_ok(t,h,A,B):
    cnt = 0 # 必要な攻撃回数
    for hp in h:
        cnt += max(0,math.ceil((hp-B*t)/(A-B)))
    if t >= cnt:
        return True
    else:
        return False

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N,A,B = (int(_) for _ in input().split())
    h = []
    max_h = 0
    for i in range(N):
        h.append(int(input()))
        max_h = max(h[i],max_h)        
    ng = -1
    ok = math.ceil(max_h/B) # 考えうる最大の攻撃回数

    # 二分探索
    while (abs(ok-ng)>1):
        mid = (ok + ng) //2
        if is_ok(mid,h,A,B):
            ok = mid
        else:
            ng = mid
    print(ok)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline

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

def judge(k):
    cnt = 0
    for h in H:
        cnt += -(-(max(h-k*B,0))//(A-B))
    if cnt <= k:
        return True
    return False

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

ans = biserch(max(H),-1,judge)
print(ans)

Submission status: Accepted

Solution code:
import math
n, a, b = [int(item) for item in input().split()]
h = []
for i in range(n):
    h.append(int(input()))
alpha_d = a-b

def is_eliminatable(num):
    avr_d = num * b
    count = 0
    for item in h:
        hp = item - avr_d
        if hp > 0:
            count += math.ceil(hp / alpha_d)
        if count > num:
            return False
    return True

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

Submission status: Accepted

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

d = A-B

def judge(k):
    cnt = 0
    remain = [max(h-k*B,0) for h in H]
    for r in remain:
        cnt += -(-r // d)
    if cnt <= k:
        return True
    else:
        return False

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

ans = biserch(10**9,-1,judge)
print(ans)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]
    
def f(x):
    s = sum([- (- max(0, h - x * B) // (A - B)) for h in H])
    if s <= x:
        return True
    else:
        return False
    
l = 0
r = 10 ** 9 + 7
while l < r:
    m = (l + r) // 2
    if f(m):
        r = m
    else:
        l = m + 1
    # print(r, l, m)
        
print(r)

Submission status: Accepted

Solution code:
N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]
    
def f(x):
    s = sum([- (- max(0, h - x * B) // (A - B)) for h in H])
    if s <= x:
        return True
    else:
        return False
    
l = 0
r = 10 ** 9 + 7
while r - l > 1:
    m = (l + r) // 2
    if f(m):
        r = m
    else:
        l = m
    # print(r, l, m)
        
print(r)

Submission status: Accepted

Solution code:
import math
N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]
    
def f(x):
    s = sum([math.ceil(max(0, h - x * B) / (A - B)) for h in H])
    if s <= x:
        return True
    else:
        return False
    
l = 0
r = 10 ** 9 + 7
while r - l > 1:
    m = (l + r) // 2
    if f(m):
        r = m
    else:
        l = m
    # print(r, l, m)
        
print(r)

Submission status: Accepted

Solution code:
import sys

def is_enough(H, A, B, T):
    cnt = 0
    diff = A - B
    base = B * T
    for h in H:
        if h <= base:
            continue

        cnt += (h - base + diff - 1) // diff
        if cnt > T:
            return False

    return True


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

    R = (max(H) + B - 1) // B
    L = (min(H) + A - 1) // A
    while R != L:
        c = (R + L) // 2
        if is_enough(H,  A, B, c):
            R = c
        else:
            L = c + 1

    return L


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

Submission status: Accepted

Solution code:
import math
N,A,B = map(int,input().split())
H = []
for i in range(N):
  H.append(int(input()))
ok = -1
ng = int(sum(H)/B)
while ng-ok > 1:
  mid = (ok+ng)//2
  cnt = 0
  for i in range(N):
    if H[i] < B*mid:
      None
    else:
      cnt += math.ceil((H[i]-B*mid)/(A-B))
  if cnt > mid:
    ok = mid
  else:
    ng = mid
print(ng)

Submission status: Accepted

Solution code:
from math import ceil


def widespread(N: int, A: int, B: int, H: list)->int:
    def killable_by(T: int)->bool:
        return sum(max(0, ceil((h-B*T)/(A-B))) for h in H) <= T

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

    return r


if __name__ == "__main__":
    N = 0
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    ans = widespread(N, A, B, H)
    print(ans)

Submission status: Accepted

Solution code:
import math
n,a,b=map(int,input().split())
h=[int(input())for i in range(n)]
def f(x):
    s=sum([math.ceil(max(0,i-x*b)/(a-b))for i in h])
    if s<=x:
        return True
    else:
        return False
l=10**9+7
r=0
while l-r>1:
    k=(l+r)//2
    if f(k):
        l=k
    else:
        r=k
print(l)

Submission status: Accepted

Solution code:
import sys
def p(*a):
  s=" ".join(map(str,a))
  #print(s)
  sys.stderr.write(s+"\n")

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

import math
C=A-B
TMax=math.ceil(max(H)/B)
TMin=1
p(A,B,C,TMax,TMin)

def canWipe(t):
  x=0
  for h in H:
    x+=max(0,math.ceil((h-B*t)/C))
    if x>t: break
  return (t>=x)

t=TMax
ans=t
while TMax!=TMin:
  t=(TMax+TMin)//2
  if canWipe(t):
    ans=t
    TMax=t
  else:
    TMin=t+1
print(ans)

Submission status: Accepted

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

h = [int(input()) for i in range(n)]
diff = a-b
def solve(num):
  kaisu = 0
  for i in range(n):
    if -((-(h[i]-num*b))//diff) > 0:
      kaisu += -((-(h[i]-num*b))//diff)
  if kaisu <= num:
    return True
  else:
    return False
    
ng = 0
ok = 1000000001

while abs(ok-ng)>1:
  mid = (ok+ng)//2
  if solve(mid):
    ok = mid
  else:
    ng = mid
#  print(ng,ok)
print(ok)

Submission status: Accepted

Solution code:
def d_widespread(N, A, B, H):
    from math import ceil
    lower_limit = 0
    upper_limit = max(H) // B + 1  # 多くともこの回数だけ魔法を使えば全滅できる

    def can_defeat(t):
        # t回で魔物を全滅させられるか
        # Bt以下の体力の魔物は魔法の巻き添えで倒す(直接狙う必要がない)
        time_defeat_all = sum([ceil((h - B * t) / (A - B)) for h in H if h > B * t])
        return time_defeat_all <= t

    while upper_limit - lower_limit > 1:
        mid = (lower_limit + upper_limit) // 2
        if can_defeat(mid):
            upper_limit = mid
        else:
            lower_limit = mid
    return upper_limit

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

Submission status: Accepted

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

mh = max(H)
x = mh//A
y = -(-mh//B)

def judge(cnt):
    d = A-B
    tmp = 0
    for h in H:
        nh = max(h-B*cnt,0)
        tmp += -(-nh//d)
    if cnt >= tmp:
        return True
    else:
        return False

def biserch(left=x,right=y):
    while right-left>1:
        middle = (left+right) // 2
        if judge(middle) is True:
            right = middle
        else:
            left = middle
    return right

rec = biserch()
print(rec)

Submission status: Accepted

Solution code:
n, a, b = map(int, input().split())
hlist = [int(input()) for _ in range(n)]
maxn = (max(hlist) + b - 1) // b

def enough(t):
  c = 0
  for h in hlist:
    if h - b * t > 0:
      c += (h - b * t + a - b - 1) // (a - b)
  return c <= t

l, r = 0, maxn
while l != r:
  mid = (l + r) // 2
  if enough(mid):
    r = mid
  else:
    l = mid + 1
print(l)

Submission status: Accepted

Solution code:
N,A,B=map(int,input().split())
H=[int(input()) for i in range(N)]
M=(max(H)+B-1)//B
search=(1,2)
def check(H,k):
    cnt=0
    for i in range(N):
        x=H[i]-k*B
        if x>0:
            cnt+=(x+A-B-1)//(A-B)
    if cnt<=k:return True
    else:return False

mincan=M
maxcant=0
while True:
    k=M*search[0]//search[1]
    if check(H,k):
        if k==maxcant+1:
            ans=k
            break
        mincan=min(mincan,k)
        search=(search[0]*2-1,search[1]*2)
    else:
        if k==mincan-1:
            ans=k+1
            break
        maxcant=max(maxcant,k)
        search=(search[0]*2+1,search[1]*2)
print(ans)

Submission status: Accepted

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

from math import ceil

ng,ok = 0,10**9+1
while abs(ok-ng)>1:
    mid = (ng+ok)//2
    cnt = 0
    for i in range(N):
        cnt += max(ceil((H[i] - B*mid)/(A-B)) ,0)
    if cnt <= mid:
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A

#B

#C
"""
n = I()
s = IR(n)
su = sum(s)
dp = [[0 for i in range(su+1)] for j in range(n)]
dp[0][s[0]] = 1
for i in range(n):
    dp[i][0] = 1
for i in range(1,n):
    for j in range(su+1)[::-1]:
        if s[i]+j <= su:
            dp[i][s[i]+j] = max(dp[i][s[i]+j],dp[i-1][j])
        dp[i][j] = max(dp[i][j],dp[i-1][j])
for i in range(su+1)[::-1]:
    if dp[n-1][i] == 1 and i%10 != 0:
        break
print(i)
"""

#D
n,a,b = LI()
h = IR(n)
l = 0
r = math.ceil(max(h)/b)
while r-l > 1:
    m = (l+r)//2
    k = 0
    for i in range(n):
        k += max(0,math.ceil((h[i]-b*m)/(a-b)))
        if k > m:break
    if k > m:
        l = m
    else:
        r = m
print(r)
#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

h.sort()

c = a - b
top = h[n - 1] // b + 1
bottom = 1
while top - bottom > 0:
    temp = (top + bottom) // 2
    p = bisect_right(h, temp * b)
    count = 0
    for i in range(p, n):
        count += (h[i] - temp * b) // c
        if h[i] % c != 0:
            count += 1
    if count > temp:
        bottom = temp + 1
    else:
        top = temp
    #print(top, bottom, count, temp)

print(top)

Submission status: Accepted

Solution code:
from math import ceil
N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]
A -= B  # Aを追加ダメージ扱いにする


ok, ng = 10 ** 9, 0
while abs(ok - ng) > 1:
    X = (ok + ng) // 2
    H_damaged = [h - (B * X) for h in H if h - (B * X) > 0]
    Need = sum([ceil(h / A) for h in H_damaged])

    if X >= Need:
        ok = X
    else:
        ng = X

print(ok)

Submission status: Accepted

Solution code:
import math

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

def erase(k):
  bomb_time = 0
  for i in h:
    normal_damage = b * k
    if i <= normal_damage:
      break
    i -= normal_damage
    bomb_time += math.ceil(i / (a-b))
    if bomb_time > k:
      return False
  return True

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

Submission status: Accepted

Solution code:
n,a,b,*h=map(int,open(0).read().split());i,j=0,2**30
while j-i>1:
 k=c=(j+i)//2
 for t in h:c+=min(0,(b*k-t)//(a-b))
 if c<0:i=k
 else:j=k
print(j)

Submission status: Accepted

Solution code:
n,a,b,*h=map(int,open(0).read().split());i,j=0,max(h)
while j-i>1:
 k=c=(j+i)//2
 for t in h:c+=min(0,(b*k-t)//(a-b))
 if c<0:i=k
 else:j=k
print(j)

Submission status: Accepted

Solution code:
n,a,b,*h=map(int,open(0).read().split());i,j=0,-(-max(h)*n//a)
while j-i>1:
 k=c=(j+i)//2
 for t in h:c+=min(0,(b*k-t)//(a-b))
 if c>=0:j=k
 else:i=k
print(j)

Submission status: Accepted

Solution code:
n,a,b,*h=map(int,open(0).read().split())
i,j=0,-(-max(h)*n//a)
while j-i>1:
 k=c=(j+i+1)//2
 for t in h:c+=min(0,(b*k-t)//(a-b))
 if c>=0:j=k
 else:i=k
print(j)

Submission status: Accepted

Solution code:
n,a,b,*h=map(int,open(0).read().split())
i,j=0,-(-max(h)*n//a)
while True:
  if j-i<2:
    print(j)
    break
  k=c=(j+i+1)//2
  for t in h:
    t-=b*k
    if t>0:
      c+=-t//(a-b)
  if c>=0:
    j=k
  else:
    i=k

Submission status: Accepted

Solution code:
from math import ceil
n,a,b=map(int,input().split())
H=[int(input()) for _ in range(n)]
Mh=max(H)
left,right=Mh//a,Mh//b+1
while right-left>1:
    mid=(left+right)//2
    cnt=0
    for i in range(n):
        cnt+=ceil(max(H[i]-mid*b,0)/(a-b))
    if cnt<=mid:
        right=mid
    else:
        left=mid
print(right)

Submission status: Accepted

Solution code:
from math import ceil

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

def f(k):
    return sum([ceil((hi-B*k)/(A-B)) for hi in h if hi-k*B>0])<=k

l,r=0,ceil(max(h)/B)

while r-l>1:
    if f((l+r)//2):
        r=(l+r)//2
    else:
        l=(l+r)//2

print(r)

Submission status: Accepted

Solution code:
import math


def solve(N, A, B, Hs):
    k_min = 1
    k_max = 10 ** 9
    d = A - B
    # print(N, ",", A, ",", B, ",", Hs)

    def find(k):
        # print("find %d" % k)
        kc = sum([max(math.ceil((h - B * k) / d), 0) for h in Hs])
        return kc <= k

    def bin_search(k_min, k_max):
        if k_max - k_min <= 1:
            if find(k_min):
                return k_min
            return k_max
        # print("find %d, %d" % (k_min, k_max))
        k_mid = (k_max + k_min) // 2
        m = find(k_mid)
        if m:
            return bin_search(k_min, k_mid)
        else:
            return bin_search(k_mid, k_max)

    return bin_search(k_min, k_max)

if __name__ == "__main__":
    N, A, B = tuple(map(int, input().split(" ")))
    Hs = []
    for _ in range(N):
        Hs.append(int(input()))
    print(solve(N, A, B, Hs))

Submission status: Accepted

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

from math import ceil

ng,ok = 0,10**9+1
while abs(ok-ng)>1:
    mid = (ng+ok)//2
    cnt = 0
    for i in range(N):
        cnt += max(ceil((H[i] - B*mid)/(A-B)) ,0)
    if cnt <= mid:
        ok = mid
    else:
        ng = mid

print(ok)

Submission status: Accepted

Solution code:
import math

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

def check(x):
    defaultDamage = b * x
    cnt = 0
    for h in hList:
        if h > defaultDamage:
            cnt += math.ceil((h - defaultDamage) / (a - b))
    return cnt <= x

left = 0
right = 10 ** 9
while abs(right - left) > 1:
    center = (left + right) // 2
    if check(center):
        right = center
    else:
        left = center
print(right)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
N, A, B = map(int, input().split())
h = []
for _ in range(N):
    h.append(int(input()))


def check(m):
    cnt = 0
    for i in range(N):
        cnt += max(-(-(h[i]-m*B)//(A-B)), 0)
    return cnt <= m

l = 0
r = 10**9+1
while r-l != 1:
    c = (l+r)//2
    if check(c):
        r = c
    else:
        l = c
print(r)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
N, A, B = map(int, input().split())
h = []
for _ in range(N):
    h.append(int(input()))


def check(m):
    cnt = 0
    for i in range(N):
        cnt += max(-(-(h[i]-m*B)//(A-B)), 0)
    return cnt <= m


def binary_search(l, r):
    c = (l+r)//2
    if r-l == 1:
        return l if check(c) else r

    if check(c):
        return binary_search(l, c)
    else:
        return binary_search(c, r)

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

Submission status: Accepted

Solution code:
import math


# 条件式「condition」を満たす引数tの中で
# 最小となるtを出力
class binarySearch:
    # 添え字「t」によってソート済みリストを二分探索
    def __init__(self, limit):
        self.limit = limit  # 上限
        self.t = 0

    # 問題によってここを書き換える
    def condition(self, h, a, b):
        if self.t < 0:
            return False
        count = 0
        for i in range(len(h)):
            if h[i] > b * self.t:
                count += math.ceil((h[i] - b * self.t) / (a - b))
        if count > self.t:
            return False
        else:
            return True

    def search(self, h, a, b):
        low = 0
        high = self.limit
        self.t = int((low + high) / 2)
        while high >= low:
            out = self.condition(h, a, b)
            if not out:
                low = self.t + 1
            else:
                high = self.t - 1
            self.t = int((low + high) / 2)
        return self.t + 1


n, a, b = [int(i) for i in input().split()]
h = [0 for _ in range(n)]
for i in range(n):
    h[i] = int(input())
binary = binarySearch(limit=math.ceil(max(h) / 1))
print(binary.search(h, a, b))