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: Wrong Answer

Solution code:
import numpy as np
N, A, B = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = np.sort(H)[::-1]
attack = np.ones(N).astype(np.int64)
attack *= B
attack[0] = A
count = 0
p = int(H[0]/A)
order = 0
while p>=10:
    p /= 10
    order+=1
while H[0]>0:
    if H[0]/(A*10**(order)) > 1:
        H -= attack*10**(order)
        H = np.sort(H)[::-1]
        count += 10**(order)
    else:
        order -= 1
        if order<0:
            break
        H -= attack*10**(order)
        H = np.sort(H)[::-1]
        count += 10**(order)
    print (order)
while H[0]>0:
    H -= attack
    H = np.sort(H)[::-1]
    count += 1
print (count)

Submission status: Wrong Answer

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

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

enemy=N
counter=0

while enemy>0:
    if max(h)>=A*1000:
        atk=h.index(max(h))
        num=int((max(h)-A)/(10*N))
        for i in range(N):
            h[i]-=(B*num)
        h[atk]+=(num*(B-A))
        counter+=num





    atk=h.index(max(h))
    for i in range(N):
        h[i]-=B
    h[atk]+=(B-A)
    counter+=1

    for i in range(N):
        if h[i]<=0:
            h[i]=0
            enemy-=1

 #   print(h)
print(counter)

Submission status: Wrong Answer

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


if (max(h)/A<10000):
    alive=[i for i in h if i > 0]
    t=0

    while (alive):
        boss=h.index(max(h))
        h=[i-B for i in h]
        h[boss]=h[boss]+B-A
        t+=1
        alive=[i for i in h if i > 0]
    print(t)
else:
    total_h=(sum(h))

    t=total_h/(len(h)*(B)+(A-B))
    print(t)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, A, B = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = np.sort(H)[::-1]
attack = np.ones(N).astype(np.int64)
attack *= B
attack[0] = A
count = 0
p = int(H[0]/A)
order = 0
while p>=10:
    p /= 10
    order+=1

while H[0]>0:
    if H[0]/(A*10**(order)) > 1:
        H -= attack*10**(order)
        H = np.sort(H)[::-1]
        count += 10**(order)
    else:
        order -= 1
        if order<0:
            H -= attack
            H = np.sort(H)[::-1]
            count += 1
        else:
            H -= attack*10**(order)
            H = np.sort(H)[::-1]
            count += 10**(order)
print (count)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
m=[]
for i in range(n):
    m.append(int(input()))
m.sort(reverse=True)
print(m)

attack=0
#攻撃
while m[0] > 0:
    for i in range(len(m)):
        if i == 0:
            m[i]= m[i] - a
        else:
            m[i]= m[i] - b
    m.sort(reverse=True)
    attack += 1
print(attack)

Submission status: Wrong Answer

Solution code:
n,a,b=map(int,input().split())
dm=a+b*(n-1)
data=[]
for i in range(n):
    data.append(int(input()))
ans=0
while len(data):
    x=(sum(data)//dm)+(sum(data)%dm!=0)
    tmp=x
    ans+=tmp
    data=[n-x*b for n in data if n-x*b>0]
    while 1:
        if len(data)==0:
            break
        if x-(data[0]//(a-b)+(data[0]%(a-b)!=0))>=0:
            x=x-(data[0]//(a-b)+(data[0]%(a-b)!=0))
            del data[0]
        else:
            data[0]-=x*(a-b)
            break
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, A, B = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = np.sort(H)[::-1]
attack = np.ones(N).astype(np.int64)
attack *= B
attack[0] = A
count = 0
p = int(H[0]/A)
order = 0
while p>=10:
    p /= 10
    order+=1

while H[0]>0:
    if int(H[0]/A)>0:
        H -= attack*10**(order)
        H = np.sort(H)[::-1]
        count += 10**(order)
    else:
        H -= attack
        H = np.sort(H)[::-1]
        count += 1
print (count)

Submission status: Wrong Answer

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


h.sort(reverse=True)
result = 0
tmp = 0
while(len(h) != 0):
    h.sort(reverse=True)
    if h[0]//a == 0:
        tmp = 1
    else:
        tmp = h[0]//a
    h[0] -= tmp*a
    for i in range(1, len(h)):
        h[i] -= tmp*b
    h = list(set(h) - set(filter(lambda x : x <= 0, h)))
    result += tmp

print(result)

Submission status: Wrong Answer

Solution code:
import math

x=list(map(int,input().split(" ")))
n=x[0]
y=x[1]
z=x[2]

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

a.sort(reverse=True)
count=0
for c in a:
    if c>=count*z:
        count+=math.ceil((c-count*z)/y)
print(count)

Submission status: Wrong Answer

Solution code:
import numpy as np
N, A, B = list(map(int,input().split()))
H = []
for i in range(N):
    H.append(int(input()))
H = np.sort(H)[::-1]
attack = np.ones(N).astype(np.int64)
attack *= B
attack[0] = A
count = 0
while H[0]>0:
    p = int(H[0]/A)
    if p>0:
        H -= attack*p
        H = np.sort(H)[::-1]
        count += p
    else:
        H -= attack
        H = np.sort(H)[::-1]
        count += 1
print (count)

Submission status: Time Limit Exceeded

Solution code:
import math

def func(h, a, b, count):
  ans = 0
  for v in h:
    if v > b * count:
      ans += math.ceil((v-b*count) / (a-b))
      
  return ans <= count

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

for i in range(n):
  # heapqを最大値を取り出すように使いたいのでマイナスにする
  h.append(int(input()))

delta = a-b
start = 1
end = math.ceil(max(h) / b)
middle = (end + start) // 2

# 二分探索する、終了条件はぶっちゃけわからん
while True:
  if(func(h,a,b,middle)):
    end = middle
  else:
    start = middle
    
  middle = (end + start) // 2
  if (end - start) == 1:
    break
    
print(end)

Submission status: Time Limit Exceeded

Solution code:
from heapq import heapify, heappop, heappush
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import statistics # Pythonのみ
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():

    n, a, b = map(int, input().split())
    l = [int(input()) for i in range(n)]
    q = []
    for i in l:
        heappush(q, -i)
    cnt = 0
    while True:
        nq = []
        v = -heappop(q)
        if v-a > 0:
            heappush(nq, -(v-a))
        for i in q:
            if -i-b > 0:
                heappush(nq, -(-i-b))
        cnt += 1
        if not nq:
            break
        else: q=nq
    print(cnt)


resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7
#mod = 998244353
INF = 10**18
eps = 10**-7

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

h = [int(readline()) for i in range(N)]

C = A-B
ng = 0 #条件を常に満たさない
ok = INF #条件を常に満たす

def judge(mid):
    ans = 0
    for hi in h:
        ans += max(0,(hi-mid*B+C-1)//C)
    if ans <= mid:
        return True
    return False

while ok - ng > 1:
    mid = (ok + ng) // 2
    if judge(mid):
        ok = mid
    else:
        ng = mid
    #okが答えとなる
print(ok)

Submission status: Time Limit Exceeded

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

import heapq  # heapqライブラリのimport
#heapq.heapify(a)  # リストを優先度付きキューへ
#heapq.heappop(a)  # 最小値の取り出し
#heapq.heappush(a, -2)

heapq.heapify(h)

#直撃a、爆風b
cnt=1
while 1:
    tmp=heapq.heappop(h)*(-1)
    tmp=tmp-a+b
    heapq.heappush(h,(-1)*tmp)
    
    if h[0]*(-1)-b*cnt<=0:
        print(cnt)
        break
    cnt+=1

Submission status: Time Limit Exceeded

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

import heapq  # heapqライブラリのimport
#heapq.heapify(a)  # リストを優先度付きキューへ
#heapq.heappop(a)  # 最小値の取り出し
#heapq.heappush(a, -2)

heapq.heapify(h)

#直撃a、爆風b
cnt=1
while 1:
    tmp=heapq.heappop(h)*(-1)
    tmp=tmp-a+b
    heapq.heappush(h,(-1)*tmp)

    tmp=heapq.heappop(h)*(-1)
    
    if tmp-b*cnt<=0:
        print(cnt)
        break
    heapq.heappush(h,tmp*(-1))
    cnt+=1

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
def solve():
    N, A, B = map(int, input().split())
    H = [int(input()) for _ in range(N)]
    top = max(H)+1
    total = sum(H)
    bottom = 1
    mid = (top+bottom)//2
    while bottom+1<top:
        cnt = 0
        for i in range(N):
            cnt += max(ceil((H[i]-B*mid)/(A-B)),0)
        if cnt>mid:
            bottom = mid+1
        else:
            top = mid+1
        mid = (top+bottom)//2
    ans = mid
    return ans
print(solve())

Submission status: Time Limit Exceeded

Solution code:
from numpy import ceil,array,sum
import sys

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

def is_ok(m):

    tmp = h - m*B

    if not any(tmp):
        return True

    tmp = tmp[tmp>0]

    rem = 0
    for i in tmp:
        rem += ceil(i/(A-B))
    
    if rem > m:
        return False

    return True

N,A,B = map(int,input().split())
h = array(list(int(input()) for _ in range(N)))
s = sum(h)
##二分散策

r = 10**9
l = 0

while abs(l-r) > 1:

    m = (r+l)//2

    if is_ok(m):
        r = m
    else:
        l = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
from numpy import ceil,array,sum

def is_ok(m):

    tmp = h - m*B

    if not any(tmp):
        return True

    rem = sum([ceil(i/(A-B)) for i in tmp[tmp>0]])
    
    if rem > m:
        return False

    return True

N,A,B = map(int,input().split())
h = array(list(int(input()) for _ in range(N)))
s = sum(h)
##二分散策

r = 10**9
l = 0

while abs(l-r) > 1:

    m = (r+l)//2

    if is_ok(m):
        r = m
    else:
        l = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
from numpy import ceil,array,sum

def is_ok(m):

    tmp = h - m*B

    if not any(tmp):
        return True

    rem = 0
    for i in tmp[tmp>0]:
        rem += ceil(i/(A-B))

    if rem > m:
        return False

    return True

N,A,B = map(int,input().split())
h = array(list(int(input()) for _ in range(N)))
s = sum(sum(h))
##二分散策

r = 10**10
l = 0

while abs(l-r) > 1:

    m = (r+l)//2

    if is_ok(m):
        r = m
    else:
        l = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
import sys
def waru(n,t):
  if n%t==0:
    return n//t
  else:
    return (n//t)+1
s=0
L=list()
N,A,B=map(int,input().split())
for i in range(N):
  h=int(input())
  L.append(h)
c=sum(L)//(A+B*(N-1))
t=(max(L)//B)+1
for i in range(c,t+1):
  R=[j-i*B for j in L if j-i*B>0]
  R=[waru(i,A-B) for i in R]
  if sum(R)<=i:
    print(i)
    sys.exit()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
n,a,b = map(int,input().split())
h = [int(input()) for _ in range(n)]
l = 0
r = 10**18

def f(x):
    res = 0
    for i in range(n): res += ceil(max(0,(h[i]-b*x))/(a-b))
    return res <= x

while l+1 < r:
    m = (l+r)//2
    if f(m): r = m
    else: l = m
print(r)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

gap = a-b
count = 0

while True:
    if np.count_nonzero(h<=0) == n:
        break
    h -= b
    h[np.argmax(h)] -= gap
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
H = []
for _ in range(N):
    H.append(int(input()))
H = sorted(H)
def check(x):
    cnt = 0
    for h in H:
        if h > x * B:
            tmp = (h - x*B) // (A-B)
            #切り上げ
            if tmp * (A-B) != h - x*B: tmp += 1
            cnt += tmp
    if cnt <= x:
        return True
    else:
        return False
# (l,r]
def bisect(l,r):
    if r - l == 1: return r
    mid = (l+r) // 2
    if check(mid):
        return bisect(l,mid)
    else:
        return bisect(mid,r)
    
print(bisect(0,10**40))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N, A, B = map(int,input().split())
h = []
for _ in range(N):
    h.append(int(input()))

def solve(n):
    H = np.array(h)
    H -= B * n
    cnt = 0
    for i in H:
        cnt += (i - 1) // (A - B) + 1
    return cnt <= n

left = 0
right = 10 ** 9

while left + 1 < right:
    mid = (left + right) // 2
    if solve(mid):
        right = mid
    else:
        left = mid

print(right)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil

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


def defeatable(k):
    hb = [max([h - k * b, 0]) for h in hs]
    n_attack = sum([ceil(h / (a - b)) for h in hb])
    return n_attack <= k


l, r = 0, 10 ** 14

while r - l > 1:
    m = (l + r) // 2

    if defeatable(m):
        r = m
    else:
        l = m

print(r)

Submission status: Time Limit Exceeded

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

ma = h[-1]//B
mi = 0
m = (ma+mi)//2

from bisect import bisect
h_m = [i-B*m for i in h]
h_m1 = [i-B*(m-1) for i in h]
h_m = h_m[bisect(h_m,0):]
h_m1 = h_m1[bisect(h_m1,0):]
while not (m>=count_turn(h_m,A-B) and m-1<count_turn(h_m1,A-B)):
  if m>=count_turn(h_m,A-B):
    ma = m
  else:
    mi = m+1
  m = (ma+mi)//2  
  h_m = [i-B*m for i in h]
  h_m1 = [i-B*(m-1) for i in h]
  h_m = h_m[bisect(h_m,0):]
  h_m1 = h_m1[bisect(h_m1,0):]
  
print(m)

Submission status: Time Limit Exceeded

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
    if sum([int(i<=0) for i in tmp]) == N:
        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: Time Limit Exceeded

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
    if sum([int(i<=0) for i in tmp]) == N:
        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))
m = max(h)
s = sum(h)

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: Time Limit Exceeded

Solution code:
from math import ceil
from copy import deepcopy


def check(k):
    tmp = h[:]
    for i in range(N):
        tmp[i] -= B*k
    if sum([int(i<=0) for i in tmp]) == N:
        return True

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

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

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

left = -1
right = 1e15

while abs(left-right) > 1:

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

print(int(right))

Submission status: Time Limit Exceeded

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
    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: Time Limit Exceeded

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
    return True if t>=rt else False

l,r=0,-1*(-1*sumh//b)
while r-l!=1:
    m = (l+r)//2
    if nibu(m):r=m
    else:l=m

print(r)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
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: Time Limit Exceeded

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: Time Limit Exceeded

Solution code:
import heapq

def check(h, T, A, B):
    # T回の爆破でいける？ -> BがT回行われる下で、残ったモンスターをT回のA - Bダメ攻撃で倒せる？
    que = []
    for hi in h:
        if hi - B * T > 0:
            que.append(- hi + B * T)
    que.sort()
    A_count = 0
    for q in que:
        count = (-q + (A - B) - 1) // (A - B)
        A_count += count
    
    return A_count <= T


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

lower, upper = 0, 10 ** 15

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

print(upper)

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
sys.setrecursionlimit(10 ** 6)
def main():
    import sys
    input = sys.stdin.readline
    
    n,a,b = map(int,input().split())
    H = []
    for _ in range(n):
        h = int(input())
        H.append(-h)
    heapq.heapify(H)
    ans = 0
    dm = 0
    d = a-b
    while True:
        mx = heapq.heappop(H)
        if mx+dm <0:
            mx += d
            dm += b
            ans += 1
            heapq.heappush(H, mx)
        else:
            break
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import heapq
n,a,b = map(int,input().split())
H = []
for _ in range(n):
    h = int(input())
    H.append(-h)
heapq.heapify(H)
ans = 0
dm = 0
d = a-b
while True:
    mx = heapq.heappop(H)
    if mx+dm <0:
        mx += d
        dm += b
        ans += 1
        heapq.heappush(H, mx)
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
n,a,b = map(int,input().split())
H = []
for _ in range(n):
    h = int(input())
    H.append(-h)
heapq.heapify(H)
ans = 0
dm = 0
d = a-b
while True:
    mx = heapq.heappop(H)
    if mx+dm <0:
        mx += d
        dm += b
        ans += 1
        heapq.heappush(H, mx)
    else:
        break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
class Range_BIT:
    def __init__(self, n):
        self.n = n
        self.bit0 = [0]*(n+1)
        self.bit1 = [0]*(n+1)
    
    def _Add(self, k, x, is_bit0=True):
        if is_bit0 == True:
            data = self.bit0
        else:
            data = self.bit1
        while k <= self.n:
            data[k] += x
            k += k & -k
    
    def _Get(self, data, k):
        s = 0
        while k:
            s += data[k]
            k -= k&-k
        return s
    
    """ 配列の獲得 """
    def Array(self):
        array = [0]*(n+1)
        for i in range(self.n):
            array[i] = self.Get(i+1,i+2)
        return array[:-1]
    
    """ 区間[l:r)に対してxを加算 """
    def Add(self, l, r, x):
        self._Add(l, -x*(l-1), is_bit0=True)
        self._Add(r, x*(r-1), is_bit0=True)
        self._Add(l, x, is_bit0=False)
        self._Add(r, -x, is_bit0=False)
    
    """ 区間[l:r)の総和 """
    def Get(self, l, r):
        Pi = self._Get(self.bit1, r-1)*(r-1) - self._Get(self.bit1, l-1)*(l-1)
        Qi = self._Get(self.bit0, r-1) - self._Get(self.bit0, l-1)
        return Pi+Qi

n,a,b = map(int,input().split())
d = a-b
rbit = Range_BIT(n)
for i in range(n):
    h = int(input())
    rbit.Add(i+1, i+2, h)
ans = 0
while True:
  arr = rbit.Array()
  mx = max(arr)
  idx = arr.index(mx)
  if mx <= 0:
    break
  rbit.Add(1,n+1,-b)
  rbit.Add(idx+1, idx+2, -d)
  ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

# x回で全モンスター倒せるかどうかをにぶちゃん(にぱー)

import math

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

Submission status: Time Limit Exceeded

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

# x回で全モンスター倒せるかどうかをにぶちゃん(にぱー)

import math

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

while abs(right-left) > 1:
    center = (right+left)//2
    
    if check(center) == True:
        right = center
    elif check(center) == False:
        left = center
        
print(right)

Submission status: Time Limit Exceeded

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

# x回で全モンスター倒せるかどうかをにぶちゃん(にぱー)

left = -1
right = 10**9+7

def check(x):
    for i in range(N):
        res = h[i] - B*x
        if res >= (A-B)*x:
            return False
    return True

while abs(right-left) > 1:
    center = (right+left)//2
    
    if check(center) == True:
        right = center
    elif check(center) == False:
        left == center
        
print(center)

Submission status: Time Limit Exceeded

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

# x回で全モンスター倒せるかどうかをにぶちゃん(にぱー)

left = 0
right = 10**10

def check(x):
    for i in range(N):
        res = h[i] - B*x
        if res >= (A-B)*x:
            return False
    return True

while abs(right-left) > 1:
    center = (right+left)//2
    
    if check(center) == True:
        right = center
    elif check(center) == False:
        left == center
        
print(center)

Submission status: Time Limit Exceeded

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,hit):
    all_b = num*b
    cnt=0
    for i in range(len(hit)):
        rest = hit[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:
    hit = copy.deepcopy(h)
    mid=(l+r)//2

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

Submission status: Time Limit Exceeded

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,hit):
    all_b = num*b
    cnt=0
    for i in range(len(hit)):
        rest = hit[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**18
while r-l>1:
    hit = copy.deepcopy(h)
    mid=(l+r)//2

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

Submission status: Time Limit Exceeded

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,hit):
    all_b = num*b
    for i in range(len(hit)):
        hit[i] -= all_b
    cnt=0
    for i in range(len(hit)):
        if hit[i]>0:
            cnt+=(hit[i] - 1) // (a-b) + 1
    if cnt <= num:
        return True
    else:
        return False

import copy
l=0
r=10**18
while r-l>1:
    hit = copy.deepcopy(h)
    mid=(l+r)//2

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

Submission status: Time Limit Exceeded

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


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

import copy
l=0
r=10**18
while r-l>1:
    hit = copy.deepcopy(h)
    mid=(l+r)//2

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

Submission status: Time Limit Exceeded

Solution code:
N,A,B = map(int,input().split())
H = []
Count = []
List = []
for i in range(N):
  H.append(int(input()))
for k in range(max(H)//A+N):
  H.append(max(H)+B-A)
  H.remove(max(H))
  for j in range(len(H)):
    List.append(H[j]-B)
  Count.append(1)
  H = List
  List = []
  if max(H)<=0:
    break
print(sum(Count))

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

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