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:
# ABC063 D
N, A, B = map(int, input().split())
h = [0] * N
for i in range(N):
    h[i] = int(input())

L = 0
R = sum((h[i]-1) // A + 1 for i in range(N)) + 1
while R - L > 1:
    M = (L+R-1) // 2 + 1
    count = sum((h[i] - B*M - 1) // (A-B) + 1 for i in range(N) if h[i] - B*M > 0)
#     print(L, R, M, count)
    if count > M:
        L = M
    else:
        R = M
print((L+R-1) // 2 + 1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N,A,B = inputIL()
h = inputILs(N)

h.sort()

def count_turn(l,x):
  count = 0
  for i in l:
    count += (i+(x-1))//x
  return count




from bisect import bisect

def is_ok(n):
  h_n = [i-B*n for i in h]
  h_n = h_n[bisect(h_n,0):]
  if n>=count_turn(h_n,A-B):
    return True
  else:
    return False

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

ok = h[-1]//B+1
ng = 0
  
print(meguru_bisect(ng, ok))

Submission status: Accepted

Solution code:
import sys
from math import ceil
"""
def input():
    return sys.stdin.readline().strip()
"""
def check(k):
    tmp = list(h)
    for i in range(N):
        tmp[i] -= B*k
    
    flag = False
    for i in tmp:
        if i > 0:
            flag = True
            break
    if not flag:
        return True

    lf = 0
    for i in tmp:
        if i > 0:
            lf += ceil(i/(A-B))

    if lf <= k:
        return True
    else:
        return False

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

left = -1
right = 1e9

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))

Submission status: Accepted

Solution code:
import sys
from math import ceil

def input():
    return sys.stdin.readline().strip()

def check(k):
    tmp = list(h)
    for i in range(N):
        tmp[i] -= B*k
    
    flag = False
    for i in tmp:
        if i > 0:
            flag = True
            break
    if not flag:
        return True

    lf = 0
    for i in tmp:
        if i > 0:
            lf += ceil(i/(A-B))

    if lf <= k:
        return True
    else:
        return False

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

left = -1
right = 1e9

while abs(left-right) > 1:

    mid = (left+right)//2
    if check(mid):
        right = mid
    else:
        left = mid

print(int(right))

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

from math import ceil


def check(s):
    cnt = 0
    for hh in h:
        if s * b < hh:
            cnt += ceil((hh - s * b) / (a - b))
    return cnt <= s


n, a, b, *h = map(int, read().split())
low = 0
high = 10 ** 18
while low + 1 < high:
    mid = (low + high) // 2
    if check(mid):
        high = mid
    else:
        low = mid
print(high)

Submission status: Accepted

Solution code:
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    INF = 10**18
    MOD = 10**9 + 7
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,A,B = LI()
    H = [NI() for _ in range(N)]

    h = max(H) // B + 1
    l = 0
    while h > l+1:
        m = (h+l) // 2
        cnt = m
        for x in H:
            if x >= m * B:
                cnt -= math.ceil((x-m*B) / (A-B))
                if cnt < 0: break
        else:
            h = m
            continue
        l = m
    print(h)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import numpy as np

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

H = []

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

H = np.array(H)

def binary_search(x):
    H_tmp = H - B * x
    H_tmp = H_tmp[H_tmp > 0]
    count = ((H_tmp + A - B - 1) // (A - B)).sum()
    return x >= count

left = 0
right = 10**10

while(right - left > 1):
    mid = (left + right) // 2
    ret = binary_search(mid)
    if ret:
        right = mid
    else:
        left = mid

print(right)

Submission status: Accepted

Solution code:
def resolve():
    def f(mid):
        return sum([(x - mid * b + a - b - 1) // (a - b) for x in h if x > mid * b]) <= mid
    n, a, b = map(int, input().split())
    h = [int(input()) for _ in range(n)]
    ok, ng = 10 ** 10, 0
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if f(mid):
            ok = mid
        else:
            ng = mid
    print(ok)


if __name__ == '__main__':
    resolve()

Submission status: Accepted

Solution code:
n, a, b = map(int,input().split())
h = [ int(input()) for i in range(n)]
maxim_h =  max(h)

ok = (maxim_h + a - 1) // a * n
ng = 0
while abs(ok - ng) > 1:

    X = (ok + ng) // 2
    #X回爆発を起こす必要があると仮定する

    cnt = 0
    flag = 1
    for val in h:
        if val <= b * X:continue
        temp = (val - b * X + a - b - 1) // (a - b)
        cnt += temp

        if cnt > X:
            flag = 0
            break

    #print(X, cnt, ok)
    if flag:ok = X
    else:ng = X
print(ok)

Submission status: Accepted

Solution code:
n,a,b= map(int,input().split())
sh = sorted([int(input()) for i in range(n)],reverse=True)
sumh = sum(sh)
def nibu(t):
    rt=0
    for i in range(n):
        temp = -1*(-1*max(0,sh[i]-t*b)//(a-b))
        if temp>0:rt+=temp
        else:break
        if rt>t:return False
    return True if t>=rt else False
l=max(sh)//a
r=max(sh)//b+1
while r-l!=1:
    m = (l+r)//2
    if nibu(m):r=m
    else:l=m
print(r)

Submission status: Accepted

Solution code:
n,a,b= map(int,input().split())
sh = sorted([int(input()) for i in range(n)],reverse=True)
sumh = sum(sh)
def nibu(t):
    rt=0
    for i in range(n):
        temp = -1*(-1*max(0,sh[i]-t*b)//(a-b))
        if temp>0:rt+=-1*(-1*max(0,sh[i]-t*b)//(a-b))
        else:break
        if rt>t:return False
    return True if t>=rt else False
l=max(sh)//a
r=max(sh)//b+1
while r-l!=1:
    m = (l+r)//2
    if nibu(m):r=m
    else:l=m
print(r)

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N,A,B=map(int,input().split())

hlist=[]
mh=0
for i in range(N):
  h=int(input())
  hlist.append(h)
  mh=max(mh,h)
#print(mh,hlist)

res_dic={0:False}
def isOK(m):
  if m in res_dic:
    return res_dic[m]
  
  h2list=[]
  mh2=-float("inf")
  for i in range(N):
    h2=hlist[i]-m*B
    h2list.append(h2)
    mh2=max(h2,mh2)
  if mh2<=0:
    res_dic[m]=True
    return res_dic[m]
  
  cnt=0
  for i in range(N):
    if h2list[i]>0:
      cnt+=-(-h2list[i]//(A-B))
      
  res_dic[m]=(cnt<=m)
  return res_dic[m]

l,r=1,-(-mh//B)
while l<=r:
  mid=(l+r)//2
  #print(l,mid,r)
  if not isOK(mid-1) and isOK(mid):
    print(mid)
    break
  elif isOK(mid-1):
    r=mid-1
  else:
    l=mid+1

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.readline
N,A,B=map(int,input().split())

hlist=[]
for i in range(N):
  hlist.append(int(input()))
mh=max(hlist)
#print(mh,hlist)

def isOK(m):
  if m==0:
    return False
  
  hlist2=list(hlist)
  for i in range(N):
    hlist2[i]-=m*B
  #print(m,hlist2)
  if max(hlist2)<=0:
    return True
  
  cnt=0
  for i in range(N):
    if hlist2[i]>0:
      cnt+=-(-hlist2[i]//(A-B))
  return cnt<=m

l,r=1,mh//B+1
while l<=r:
  mid=(l+r)//2
  #print(l,mid,r)
  if not isOK(mid-1) and isOK(mid):
    print(mid)
    break
  elif isOK(mid-1):
    r=mid-1
  else:
    l=mid+1

Submission status: Accepted

Solution code:
import math

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


def check(x):
    cnt = 0
    for h in H:
        if h <= B * x:
            continue
        else:
            cnt += math.ceil((h - B * x) / (A - B))

    if cnt <= x:
        return True
    else:
        return False


lb = 0
ub = 10**15
while ub - lb > 1:
    mid = (lb + ub) // 2
    if check(mid):
        ub = mid
    else:
        lb = mid

ans = ub

print(ans)

Submission status: Accepted

Solution code:
N, A, B, *X = map(int, open(0).read().split())

ub = 10 ** 15
lb = 0
while ub - lb > 1:
    mid = (ub + lb) // 2
    cnt = 0
    for i in range(N):
        if X[i] - B * mid > 0:
            cnt += -(-(X[i] - B * mid) // (A - B))

    if cnt > mid:
        lb = mid
    else:
        ub = mid

print(ub)

Submission status: Accepted

Solution code:
n,a,b=map(int,input().split())
HP=[int(input()) for i in range(n)]
ng=0
ok=10**10
for i in range(40):
    check=(ok+ng)//2
    c=a-b
    cnt=0
    d=list(map(lambda x: x-check*b,HP))
    for j in d:
        cnt+=max(0,(j+c-1)//c)
    if check < cnt:
        ng=check
    else:
        ok=check
print(ok)

Submission status: Accepted

Solution code:
def judge(x):
    count = 0
    for hi in h:
        count += max(hi - b*x + c-1, 0)//c 
    if count<=x:
        return True
    else:
        return False

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

c= a-b

ng = 0
ok = 10**9

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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 # exist
ng = 0 # not exist
while abs(ok-ng) > 1:
    cnt = (ok + ng) // 2
    if func(cnt):
        ok = cnt
    else:
        ng = cnt
print(ok)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc063/tasks/arc075_b
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# Proble D - Widespread

import math

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

# initialization
left = 0
right = 10**10

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

    # check
    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

# output
print(right)

Submission status: Accepted

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

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


# めぐる式二部探索、mid=攻撃回数
l=-1
r=pow(10,10)
while r-l>1:
    # rは常にOK、lは常にNG。
    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  # 判定がOKのとき→範囲を左に狭める
    else:
        l=mid # 判定がNGのとき→範囲を右に狭める

print(r)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# int(input()) # 入力が1つ
from math import ceil
n, a, b = map(int, input().split()) # 入力が複数
# [int(i) for i in 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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc063/tasks/arc075_b

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)

# 操作回数をcとして決め打ち二分探索をする
# 満たす条件→すべての魔物を消し去る。その中で最小のcを探したい
# cが与えられたときにすべての魔物を消しされるかはどうやって求める？
# すべての魔物にc*Bダメージしたあとに、(A-B)ダメージをc回使うことで全滅箚せられればok


def is_ok(c):
    # 魔物を全滅させられればok
    bias = c * B
    addit = (A - B)
    c_cnt = c  # こいつは0になるまで使える
    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))

Submission status: Accepted

Solution code:
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)
            #temp += math.ceil(left/(A-B))
            #print(temp)

    if temp > T:
        return False
    else:
        return True

#print(enough(2))
ok = 10**15
ng = 0

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

Submission status: Accepted

Solution code:
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)
            temp += math.ceil(left/(A-B))
            #print(temp)

    if temp > T:
        return False
    else:
        return True

#print(enough(2))
ok = 10**15
ng = 0

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()

# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
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)

Submission status: Accepted

Solution code:
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()

# [ok, ng) - Maximum
# (ng, ok] - Minimum
# ok が 最終的な答え
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)

Submission status: Accepted

Solution code:
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,low)
print(high)

Submission status: Accepted

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

    #inf = 10**17
    #mod = 10**9 + 7

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

    # x回で出来るか
    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()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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 # -1にしとけば答えが0の時も普通に扱えるな

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

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
#063_D
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
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###False
y = max(h)###True

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

print(y)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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)

Submission status: Accepted

Solution code:
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()