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: 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
    hh = deepcopy(h)
    cnt = 0
    for i in range(n):
        hh[i] = max(hh[i] - b * c, 0)
        cnt += (hh[i] + ad - 1) // ad
    if c > cnt:
        r = c
    else:
        l = c
ans = inf
for i in range(max(0, l - 100), r + 100):
    hh = deepcopy(h)
    cnt = 0
    for j in range(n):
        hh[j] = max(hh[j] - b * i, 0)
        cnt += (hh[j] + ad - 1) // ad
    ans = min(ans, max(i, cnt))
print(ans)

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 > 1:
    c = (r + l) // 2
    hh = deepcopy(h)
    cnt = 0
    for i in range(n):
        hh[i] = max(hh[i] - b * c, 0)
        cnt += (hh[i] + ad - 1) // ad
    if c > cnt:
        r = c
    else:
        l = c
ans = inf
for i in range(max(0, l - 1000), r + 1000):
    hh = deepcopy(h)
    cnt = 0
    for j in range(n):
        hh[j] = max(hh[j] - b * i, 0)
        cnt += (hh[j] + ad - 1) // ad
    ans = min(ans, max(i, cnt))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = [int(i) for i in input().split()]
Hn = [int(input()) for _ in range(N)]
dAB = A - B

def check(X):
  base = B * X
  counts = sum([max((h - base + dAB - 1)//dAB, 0) for h in Hn])
  return counts <= X
               
def min_binary_search(check, l=0, r=1000000000000000):
    while r - l > 1:
      mid = (l + r) // 2
      if check(mid):
        r = mid
      else:
        l = mid
    return r
print(min_binary_search(check))

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

# C回以下の爆発で倒せるか
def is_all_kill(C:int):
    cnt = 0
    for HP in h:
        # あるモンスターに中心ダメージを何回与えるか
        tmp = ceil((HP-B*C)/(A-B))
        # オーバーキルの場合
        if tmp <= 0:
            continue
        cnt += tmp
    return cnt <= C

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

print(ok)

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b = map(int,input().split())
h = []
for _ in range(n):
    h.append(int(input()))
add = a - b
j = 0
while True: #n回爆発させる
    j += 1
    for i in range(n):
        h[i] -= b
        h[i] = max(h[i], 0)
    cnt = 0
    for i in range(n):
        cnt += math.ceil(h[i] / add)
    if cnt <= j:
        break
print(j)

Submission status: Time Limit Exceeded

Solution code:
import math, copy
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
amount = sum(H)
ADD = A - B
def judge(n, h):
    if amount < B * n:
        return True
    add_cnt = 0
    for i in range(N):
        add_cnt += math.ceil((h[i] - n * B) / ADD)
        if add_cnt > n:
            return False
    return True

l =0
r = 10 ** 9
while r > l + 1:
    m = (r + l) // 2
    if judge(m, copy.deepcopy(H)):
        r = m
    else:
        l = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
import math, copy
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
ADD = A - B
def judge(n, h):
    add_cnt = 0
    for i in range(N):
        add_cnt += math.ceil((h[i] - n * B) / ADD)
        if add_cnt > n:
            return False
    return True

l =0
r = 10 ** 9
while r > l + 1:
    m = (r + l) // 2
    if judge(m, copy.deepcopy(H)):
        r = m
    else:
        l = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
import math, copy
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
ADD = A - B
def judge(n, h):
    add_cnt = 0
    for i in range(N):
        h[i] -= n * B
        if h[i] > 0:
            add_cnt += math.ceil(h[i] / ADD)
    
    if add_cnt > n:
        return False
    return True

l =0
r = 10 ** 9
while r > l + 1:
    m = (r + l) // 2
    if judge(m, copy.deepcopy(H)):
        r = m
    else:
        l = m

print(r)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
h = []
count=0
for i in range(n):
  x = int(input())
  h.append(x)
#h.sort(reverse = True)
"""print([i for i, x in enumerate(l_dup) if x == 'b'])
# [1, 3]"""

while True:
  ix = h.index(max(h))
  # All element ,except ix,minus b (h.hoge -= b)
  h = list(map(lambda x: x-b,h))
  h[ix] -= (a-b)
  count+=1
  #print("h =",h,"count =",count)
  #hのすべての要素が非正ならば実行
  if all([i<=0 for i in h]):
    print(count)
    exit()

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
s=[]
ans=0
for i in range(n):
  h=int(input())
  s.append(h)
while max(s)>0:
  ans+=1
  s.sort()
  s[-1]-=a-b
  for i in range(n):
    s[i]-=b
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    q=int(input())
    h.append(q)
left=0
right=max(h)+1
def en(t):
    cnt=0
    for i in range(n):
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)!=0:
            cnt+=((h[i]-b*t)//((a-b))+1)
        if h[i]-b*t>0 and (h[i]-b*t)%(a-b)==0:
            cnt+=((h[i]-b*t)//(a-b))
    if cnt<=t:
        return  True
    return  False
while left+1<right:
    tmp=(left+right)//2
    if en(tmp):
        right=tmp
    else:
        left=tmp
print(right)

Submission status: Time Limit Exceeded

Solution code:
import heapq as hq

N, A, B = map(int, input().split())
h = []
for i in range(N):
    hq.heappush(h, -int(input()))
    
count = 0
while True:
    max_h = hq.heappop(h)
    
    if max_h >= 0:
        break
    
    h = [x + B for x in h]
    hq.heapify(h)
    hq.heappush(h, max_h + A)
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
h = []
for i in range(N):
    h.append(int(input()))
    
count = 0
while True:
    max_h = 0
    for i in range(N):
        if h[i] > max_h:
            max_h = h[i]
            max_num = i
    
    if max_h <= 0:
        break
    
    h = [x - B for x in h]
    h[max_num] += B - A
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
from math import ceil 
n,a,b=map(int,input().split())
l=[int(input()) for i in range(n)]
def check(x):
    c=0
    l1=[i-b*x for i in l]
    #print(l1)
    for i in l1: 
         c+=ceil((i)/(a-b))
    return c<=x
lo=0 
ans=-1 
hi=10**19
while lo<=hi:
    mi=(lo+hi)>>1 
    if check(mi):
        ans=mi 
        hi=mi-1
    else:
        lo=mi+1 
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
list_enemy = [int(input()) for _ in range(n)]
list_enemy.sort(reverse=True)
sub_list = list_enemy
count = 0
while len(sub_list) > 0:
  temp_list = [one_e - b for one_e in sub_list[1:] if one_e - b > 0]
  if sub_list[0] > a:
    temp_list.insert(0, sub_list[0] - a)
  sub_list = temp_list
  sub_list.sort(reverse=True)
  count += 1
print(count)

Submission status: Time Limit Exceeded

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

def enough(times):
  result = True
  damageCount = 0
  hitpoint = [monsterHitpoint[i] - otherDamage * times for i in range(monsterNum)]
  for i in range(monsterNum):
    if hitpoint[i] > 0:
      damageCount += math.ceil(hitpoint[i] / (centerDamage - otherDamage))
    if damageCount > times:
      result = False
      break
  return result
  
for i in range(monsterNum):
  monsterHitpoint[i] = int(input())
  if maxHitpoint < monsterHitpoint[i]:
    maxHitpoint = monsterHitpoint[i]
#2分探索
ansFlag = False
subtractionValue = math.ceil(maxHitpoint / otherDamage)
minTimes = subtractionValue
while not ansFlag:
  checkEnough = enough(minTimes)
  subtractionValue = subtractionValue // 2
  if checkEnough and not(enough(minTimes - 1)):
    ansFlag = True
  elif checkEnough:
    minTimes -= subtractionValue
  elif not checkEnough and (enough(minTimes + 1)):
    minTimes += 1
    ansFlag = True
  elif not checkEnough:
    minTimes += subtractionValue + 1
print(minTimes)

Submission status: Time Limit Exceeded

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

def enough(times):
  damageCount = 0
  hitpoint = [monsterHitpoint[i] - otherDamage * times for i in range(monsterNum)]
  for i in range(monsterNum):
    if hitpoint[i] > 0:
      damageCount += math.ceil(hitpoint[i] / (centerDamage - otherDamage))
  if damageCount <= times:
    return True
  else:
    return False
  
for i in range(monsterNum):
  monsterHitpoint[i] = int(input())
  if maxHitpoint < monsterHitpoint[i]:
    maxHitpoint = monsterHitpoint[i]
#2分探索
ansFlag = False
subtractionValue = math.ceil(maxHitpoint / otherDamage)
minTimes = subtractionValue
while not ansFlag:
  checkEnough = enough(minTimes)
  subtractionValue = subtractionValue // 2
  if checkEnough and not(enough(minTimes - 1)):
    ansFlag = True
  elif checkEnough:
    minTimes -= subtractionValue
  elif not checkEnough and (enough(minTimes + 1)):
    minTimes += 1
    ansFlag = True
  elif not checkEnough:
    minTimes += subtractionValue + 1
print(minTimes)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math

N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
def check(c):
    global H, A, B, N
    H_sorted = sorted(H)
    idx = bisect.bisect_left(H_sorted, B*c)
    H_greater = H_sorted[idx:]
    cnt = 0
    for h in H_greater:
        cnt += math.ceil((h-B*c)/(A-B))
    if cnt<=c:
        return True
    else:
        return False
inf = 0
sup = N*10**9
while sup-inf>1:
    mid = (sup+inf)//2
    if check(mid):
        sup = mid
    else:
        inf = mid
print(sup)

Submission status: Time Limit Exceeded

Solution code:
import bisect
import math

# N, A, B = 4, 5, 3
# H = [8, 7, 4, 2]
N, A, B = map(int, input().split())
H = [int(input()) for _ in range(N)]
def check(c):
    global H, A, B, N
    H_sorted = sorted(H)
    idx = bisect.bisect_left(H_sorted, B*c)
    H_greater = H_sorted[idx:]
    cnt = 0
    for h in H_greater:
        cnt += math.ceil((h-B*c)/(A-B))
    if cnt<=c:
        return True
    else:
        return False
inf = 0
sup = sum(H)
while sup-inf>1:
    mid = (sup+inf)//2
    if check(mid):
        sup = mid
    else:
        inf = mid
print(sup)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import numpy as np
import sys

input=sys.stdin.readline

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

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

l=np.array(l)
count=0

while np.max(l)>0:
    l=l-B
    l[np.argmax(l)]=l[np.argmax(l)]-(A-B)
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

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

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

l=np.array(l)
count=0

while np.max(l)>0:
    l=l-B
    l[np.argmax(l)]=l[np.argmax(l)]-(A-B)
    count+=1
print(count)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
import numpy as np

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

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


a=np.array(l)
count=0
while np.amax(a)>0:
    a=a-B
    a[np.argmax(a)]=a[np.argmax(a)]-A+B
    count+=1
   
print(count)

Submission status: Time Limit Exceeded

Solution code:
# https://atcoder.jp/contests/abc063/tasks/arc075_b
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


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

    ans = 0
    while True:
        strong_monster = heappop(heap)
        if strong_monster >= 0:
            break
        strong_monster += a
        for i in range(len(heap)):
            heap[i] += b
        heappush(heap, strong_monster)
        ans += 1
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import copy
def calc(n):
    d = copy.deepcopy(h)
    d = [dd - (b * n) for dd in d if (dd - (b*n)) > 0]
    a_num = sum([dd // (a - b) if (dd % (a - b) == 0) else (dd // (a - b)) + 1 for dd in d])
    if a_num <= n:
        return True
    return False

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


left = 1
right = (max(h) + 1) // (b)
middle = (left + right) // 2
middle_1 = middle - 1
calc_middle = calc(middle)
calc_middle_1 = calc(middle_1)
while not ((calc_middle) & (not calc_middle_1)):
    if not calc_middle:
        left = middle
        middle = (left + right) // 2
        middle_1 = middle - 1
    else:
        right = middle
        middle = (left + right) // 2
        middle_1 = middle - 1
    calc_middle = calc(middle)
    calc_middle_1 = calc(middle_1)
print(middle)

Submission status: Time Limit Exceeded

Solution code:
import copy
def calc(n):
    d = copy.deepcopy(h)
    d = [dd - (b * n) for dd in d if (dd - (b*n)) > 0]
    a_num = sum([dd // (a - b) if (dd % (a - b) == 0) else (dd // (a - b)) + 1 for dd in d])
    if a_num <= n:
        return True
    return False

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


left = 1
right = (max(h) + 1) // (b)
middle = (left + right) // 2
middle_1 = middle - 1
while not ((calc(middle)) & (not calc(middle_1))):
    if not calc(middle):
        left = middle
        middle = (left + right) // 2
        middle_1 = middle - 1
    else:
        right = middle
        middle = (left + right) // 2
        middle_1 = middle - 1
print(middle)

Submission status: Time Limit Exceeded

Solution code:
n, a, b = map(int, input().split())
h = []
for _ in range(n):
    h.append(int(input()))
ans = 0
while (max(h) > 0):
    h[h.index(max(h))] -= a - b
    h = [hh - b for hh in h]
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:

import bisect
import collections
import itertools


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

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

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

while min_cast < max_cast:
    cast = (min_cast + max_cast) // 2
    values= list(filter(lambda s: s > 0, map(lambda s: s - b*cast, hs)))
    need = sum(map(lambda v: (v + c - 1) // c, values))
    if need <= cast:
        max_cast = cast
    else:
        min_cast = cast + 1

print(min_cast)

Submission status: Time Limit Exceeded

Solution code:

import bisect
import collections
import itertools


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

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

min_cast = 0
max_cast = 10 ** 10
c = a-b

while min_cast < max_cast:
    cast = (min_cast + max_cast) // 2
    values= list(filter(lambda s: s > 0, map(lambda s: s - b*cast, hs)))
    need = sum(map(lambda v: (v + c - 1) // c, values))
    if need <= cast:
        max_cast = cast
    else:
        min_cast = cast + 1

print(min_cast)

Submission status: Time Limit Exceeded

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

def is_ok(x):
    t = copy.deepcopy(h)
    y = x
    for i in range(n):
        t[i] -= b * x
        if t[i] > 0:
            y -= math.ceil(t[i] / (a - b))
    return y >= 0

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

print(ok)

Submission status: Time Limit Exceeded

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

def is_ok(x):
    t = copy.deepcopy(h)
    y = x
    for i in range(n):
        t[i] -= b * x
        if t[i] > 0:
            y -= math.ceil(t[i] / (a - b))
    return y >= 0

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

print(ok)

Submission status: Time Limit Exceeded

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)
ans = 0
while len(H[H>0]):
    H = H - B
    H[np.argmax(H)] -= (A-B)
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import math
def bsearch_int(init_ng, init_ok, cond):
    ng = init_ng
    ok = init_ok
    while(abs(ok - ng) > 0):
        mid = math.floor(abs(ok + ng)/2)
        if cond(mid):
            ok = mid
        else:
            ng = mid
    return ok if ok != init_ok else -1

def condition(cnt, N, A, B, hs):
    basedmg = B*cnt
    diff = A - B
    diffcnt = 0
    for h in hs:
        if h < basedmg:
            break
        else:
            diffcnt += math.ceil((h-basedmg)/diff)
    if diffcnt > cnt:
        return False
    else:
        return True

import functools
def resolve():
    N, A, B = list(map(int, input().split(" ")))
    hs = [int(input()) for i in range(N)]
    hs.sort(reverse=True)
    print(bsearch_int(0, math.ceil(hs[0]/B), functools.partial(condition, N=N, A=A, B=B, hs=hs)))


if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

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

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

L.sort()

ans = (L[-1] // B) + 1

def f(n):
    c = n
    for v in L:
        if v > n * B:
            v -= n * B
            t = v // (A - B)
            if v % (A - B) != 0:
                t += 1
            c -= t
    return c >= 0

first = 1
for _ in range(50):
    t = (first + ans) // 2
    if f(t):
        ans = t
    else:
        first = t

print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

m = [0] * n
for i in range(n):
  m[i] = int(input())
  

m.sort()


def enough(m,a,b,T):
  cnt = 0
  for hp in m:
    if hp > b*T:
      cnt += int(math.ceil((hp - b*T)/(a-b)))
      
  return True if  cnt <= T else False

r = 10**100
#r = 30
l = 0
mid = 0

while r - l > 1:
  mid = (r+l)//2
  if enough(m,a,b,mid) == True:
    r = mid
    #print("r:",r)
  else:
    l = mid
    #print("l:",l, " r:",r)

print(r)

Submission status: Time Limit Exceeded

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 can_eliminate(l):
    return l
  if r==l+1:
    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: Time Limit Exceeded

Solution code:
import heapq

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

heapq.heapify(h)

for i in range(10**9):
    Max = -heapq.heappop(h)

    if Max <= B * i:
        break

    heapq.heappush(h, -Max + A - B)

print(i)

Submission status: Time Limit Exceeded

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

ans = 0
def bomb(H,A,B):
  global ans
  bomb_index = H.index(max(H))
  diff = A-B
  new_H = list(map(lambda x: x-B, H))
  new_H[bomb_index] = new_H[bomb_index] - diff
  ans +=1
  return(new_H)


while max(H) > 0:
  H = bomb(H,A,B)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

array = np.asarray([b]*(n-1)+[a])
hrray = np.asarray(h)

for i in range(10**9):
    hrray -= array
    if hrray[-1] <= 0:
        if max(hrray) <= 0:
            print(i+1)
            break
    hrray.sort()

Submission status: Time Limit Exceeded

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
hc = [0]*n
while st<ed-1:
    mid = (st+ed)//2
    #print(mid)
    tmp = 0
    for i in range(n):
        hc[i]=h[i]-mid*b
    for i in range(n):
        if hc[i]>0:
            tmp+=(hc[i]//(a-b))+(hc[i]%(a-b)>0)
    if tmp<=mid:
        ed = mid
    else:
        st = mid
print(ed)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np

def is_enough(H, A, B, T):
    H = H - (B * T)
    H = H[(H > 0)]

    cnt = 0
    diff = A - B
    for h in H:
        cnt += (h + diff - 1) // diff
        if cnt > T:
            return False

    return True


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

    R = (H.max() + B - 1) // B
    L = (H.min() + 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: Time Limit Exceeded

Solution code:
import sys
import numpy as np

def is_enough(H, A, B, T):
    H = H - (B * T)
    H = H[(H > 0)]

    cnt = 0
    diff = A - B
    for h in H:
        cnt += (h + diff - 1) // diff
        if cnt > T:
            return False

    return True


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

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

    return R


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

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int, input().split()))
n = A - B
h = [int(input()) for i in range(N)]
count = 0
while len(h) > 0:
	count += 1
	max_n = max(h)
	idx = h.index(max_n)

	h[idx] -= n
	h = list(map(lambda x: x-B, h))
	h = list(filter(lambda x: x > 0, h))
	
print(count)

Submission status: Time Limit Exceeded

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 ok!=ng:
    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: Time Limit Exceeded

Solution code:
n,a,b,*h=map(int,open(0).read().split());i,j=0,2**47
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: Time Limit Exceeded

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

Solution code:
import sys
input = sys.stdin.readline
import heapq
n,a,b = map(int,input().split())
q = [-int(input()) for i in range(n)]
heapq.heapify(q)
 
 
ans = 0
count = 0
while q[0]+b*count<0:
  num = heapq.heappop(q)
  num=num+(a-b)
  heapq.heappush(q,num)
  ans += 1
  count += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
n,a,b = map(int,input().split())
q = [-int(input()) for i in range(n)]
heapq.heapify(q)


ans = 0
count = 0
while q[0]+b*count<0:
  num = heapq.heappop(q)
  num=num+(a-b)
  heapq.heappush(q,num)
  ans += 1
  count += 1
print(ans)

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

def f(k):
    g=lambda x:ceil((x-B*k)/(A-B))
    return(sum(filter(lambda x:x>0,map(g,h)))<=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: Time Limit Exceeded

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

def func(n , T):
	sa=A-B
	k=0
	for x in T:
		x-=n*B
		if x>0:
			if x%sa==0:
				k+=x/sa
			else:
				k+=(x/sa+1)
		
			if n<k:
				return False
	else:
			return True

l=max(H)/A
r=max(H)/B+1
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1
	#print l,r,m,func(m,H)

print l

Submission status: Time Limit Exceeded

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

def func(n , T):
	sa=A-B
	k=0
	for x in T:
		x-=n*B
		if x>0:
			if x%sa==0:
				k+=x/sa
			else:
				k+=(x/sa+1)
		
			if n<k:
				return False
	else:
			return True

l=0
r=max(H)/B+1
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l

Submission status: Time Limit Exceeded

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

def func(n , T):
	sa=A-B
	k=0
	for x in T:
		x-=n*B
		if x>0:
			if x%sa==0:
				k+=x/sa
			else:
				k+=(x/sa+1)
		
			if n<k:
				return False
	else:
			return True

l=0
r=10**9
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l

Submission status: Time Limit Exceeded

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

def func(n , T):
	sa=A-B
	k=0
	for x in T:
		x-=n*B
		if x>0:
			if x%sa==0:
				k+=x/sa
			else:
				k+=(x/sa+1)
		
			if n<k:
				return False
	else:
			return True

l=0
r=10**15
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l

Submission status: Time Limit Exceeded

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

def func(n , T):
	S=[]
	for x in T:
		x-=n*B
		if x>0:
			S.append(x)

	sa=A-B
	for x in S:
		if x%sa==0:
			n-=x/sa
		else:
			n-=(x/sa+1)
		if n<0:
			return False
	else:
			return True

l=0
r=10**9
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l

Submission status: Time Limit Exceeded

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

def func(n , T):

	S=[]
	for x in T:
		x-=n*B
		if x>0:
			S.append(x)

	sa=A-B
	for x in S:
		if x%sa==0:
			n-=x/sa
		else:
			n-=(x/sa+1)
		if n<0:
			return False
	else:
			return True

l=0
r=10**15
while l!=r:
	m=(r+l)/2
	if func(m,H):
		r=m
	else:
		l=m+1

print l

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
from math import ceil

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

A -= B  # 爆発は追加ダメージ扱いとする

# にぶたん
ok, ng = 10 ** 9, 0
while abs(ok - ng) > 1:
    X = (ok + ng) // 2

    h = deepcopy(H)
    h = [max(hi - B * X, 0) for hi in h]
    h = [ceil(hi / A) for hi in h]

    if sum(h) <= X:
        ok = X
    else:
        ng = X

print(ok)

Submission status: Time Limit Exceeded

Solution code:
from copy import deepcopy
from math import ceil
N, A, B = map(int, input().split())
H = [int(input()) for i in range(N)]

A -= B  # 爆発は追加ダメージ扱いとする

# にぶたん
ok, ng = 10 ** 9, 0
while abs(ok - ng) > 1:
    X = (ok + ng) // 2

    h = deepcopy(H)
    h = [max(hi - B * X, 0) for hi in h]
    h = [ceil(hi / A) for hi in h]

    if sum(h) <= X:
        ok = X
    else:
        ng = X

print(ok)