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 math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
s = 0
while high - low >= 0:
    for j in range(n):
        X += max(0, math.ceil((h[j] - t * b) / (a - b)))
        #Y += max(0, math.ceil((h[j] - (t - 1) * b) / (a - b)))
    if X == t:
        print(t)
        exit()
    elif X < t:
        high = t - 1
        """for j in range(n):
            Y += max(0, math.ceil((h[j] - (t - 1) * b) / (a - b)))"""
    elif X > t:
        low = t + 1
    s = t
    t = (low + high) // 2
    X = 0
    Y = 0
for j in range(n):
            Y += max(0, math.ceil((h[j] - s * b) / (a - b)))
if Y <= s:
  print(s)
else:
  print(s + 1)

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
if high > 10**6:
    high = int(3/4 * high)
    low = int(1/4 * high)
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
def cri(p):
    if p > 0:
        return p
    else:
        return 0
while True:
    for j in range(n):
        X += cri(math.ceil((h[j] - t * b) / (a - b)))
    if X <= t:
        for j in range(n):
            Y += cri(math.ceil((h[j] - (t - 1) * b) / (a - b)))
        if Y > t - 1:
            print(t)
            exit()
        else:
            high = t - 1
    elif X > t:
        low = t + 1
    t = (low + high) // 2
    X = 0
    Y = 0

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
def avg(a, b):
    return (a + b) // 2
# t は中央番目の数
t = avg(low, high)

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
def cri(p):
    if p > 0:
        return p
    else:
        return 0
while True:
    for j in range(n):
        X += cri(math.ceil((h[j] - t * b) / (a - b)))
    if X <= t:
        for j in range(n):
            Y += cri(math.ceil((h[j] - (t - 1) * b) / (a - b)))
        if Y > t - 1:
            print(t)
            exit()
        else:
            high = t - 1
    elif X > t:
        low = t + 1
    t = avg(low, high)
    X = 0
    Y = 0

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
def cri(p):
    if p > 0:
        return p
    else:
        return 0
while True:
    for j in range(n):
        X += cri(math.ceil((h[j] - t * b) / (a - b)))
    if X <= t:
        for j in range(n):
            Y += cri(math.ceil((h[j] - (t - 1) * b) / (a - b)))
        if Y > t - 1:
            print(t)
            exit()
        else:
            high = t - 1
    elif X > t:
        low = t + 1
    t = (low + high) // 2
    X = 0
    Y = 0

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0

while True:
    for j in range(n):
        if math.ceil((h[j] - t * b) / (a - b)) > 0:
            X += math.ceil((h[j] - t * b) / (a - b))
    if X <= t:
        for j in range(n):
            if math.ceil((h[j] - (t - 1) * b) / (a - b)) > 0:
                Y += math.ceil((h[j] - (t - 1) * b) / (a - b))
        if Y > t - 1:
            print(t)
            exit()
        else:
            high = t - 1
    elif X > t:
        low = t + 1
    t = (low + high) // 2
    X = 0
    Y = 0

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
while True:
    for j in range(n):
        X += max(0, math.ceil((h[j] - t * b) / (a - b)))
        Y += max(0, math.ceil((h[j] - (t - 1) * b) / (a - b)))
    if X <= t and Y > t - 1:
        print(t)
        exit()
    elif X <= t and Y <= t - 1:
        high = t - 1
        """for j in range(n):
            Y += max(0, math.ceil((h[j] - (t - 1) * b) / (a - b)))"""
    elif X > t:
        low = t + 1
    t = (low + high) // 2
    X = 0
    Y = 0

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = math.ceil(max(h)/b)
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
while True:
    for j in range(n):
        X += max(0, math.ceil((h[j] - t * b) / (a - b)))
    if X <= t:
        for j in range(n):
            Y += max(0, math.ceil((h[j] - (t - 1) * b) / (a - b)))
        if Y > t - 1:
            print(t)
            exit()
        else:
            high = t - 1
    elif X > t:
        low = t + 1
    t = (low + high) // 2
    X = 0
    Y = 0

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b = map(int, input().split())
d = []
for i in range(n):
    d.append(input())
# [d1, d2, d3, ..., dN]
h = [int(m) for m in d]#int型に直す
#print(x)

low = 0
high = 10**9
# t は中央番目の数
t = (low + high) // 2

# 探索の下限のlowが上限のhighになるまで探索
# lowがhighに達すると数は見つからなかっTrueたということ
X = 0
Y = 0
while True:
    for j in range(n):
        X += math.ceil((h[j] - t * b) / (a - b))
    if X <= t:
        for j in range(n):
            Y += math.ceil((h[j] - (t - 1) * b) / (a - b))
        if Y > t - 1:
            print(t)
            exit()
        else:
            high = t - 1
    elif X > t:
        low = t + 1
    t = (low + high) // 2
    X = 0
    Y = 0

Submission status: Time Limit Exceeded

Solution code:
import math
n,a,b=map(int,input().split())
h=[]
for i in range(n):
    h.append(int(input()))
def sten(t):
    dh=[]
    for i in range(n):
        if h[i]-t*b>0:
            dh.append(h[i]-t*b)
    aan=0
    for i in range(len(dh)):
        aan+=math.ceil(dh[i]/(a-b))
    if aan<=t:
        return True
    else:
        return False
i=1
while True:
    if sten(i):
        print(i)
        break
    else:
        i+=1

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
"""
def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)

    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
"""
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)
arr=np.array(arr)

max_=max(arr)//B+1
min_=min(arr)//A

d=A-B

while min_!=max_:
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    sum_=0
    for x in tmp:
        sum_+=math.ceil(x/d)
    
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

print(min_)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
"""
def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)

    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
"""
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)
arr=np.array(arr)

max_=max(arr)//B+1
min_=min(arr)//A

d=A-B

while min_!=max_:
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    tmp=map(lambda x:math.ceil(x/d),tmp)
    sum_=sum(list(tmp))
    
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

print(min_)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math
"""
def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)

    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
"""
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)
arr=sorted(arr,reverse=True)
arr=np.array(arr)

max_=arr[0]//B+1
min_=arr[-1]//A

while min_!=max_:
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    
    if sum_<=mid:
        max_=mid
    else:
        min_=mid+1

print(min_)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import math

def search(min_,max_,A,B,arr):
#    print(min_,max_)
    if min_==max_:
        return min_
    mid=(max_+min_)//2
    
    tmp=arr-mid*B
    
    if len(tmp)==0:
        return search(min_,mid,A,B,arr)
    
    tmp=map(lambda x:math.ceil(x/(A-B)),tmp)
    sum_=sum(list(tmp))
    if sum_<=mid:
        return search(min_,mid,A,B,arr)
    else:
        return search(mid+1,max_,A,B,arr)
    """
    while True:
        if k<0:
            if mid==min_:
                return max_
            else:
                #failure
                return search(mid,max_,A,B,arr[:L])
        elif len(tmp)==0:
            #success
            return search(min_,mid,A,B,arr)
        x=-tmp[0]
        tmp=np.delete(tmp,0)
        k-=x//(A-B)+(x%(A-B)>0)
    """
        
    
N,A,B=list(map(int,input().split()))
arr=[]

for i in range(N):
    h=int(input())
    arr.append(h)
arr=sorted(arr,reverse=True)
arr=np.array(arr)

max_=arr[0]//B+1
min_=arr[-1]//A

ans=search(min_,max_,A,B,arr)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
from collections import deque
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def is_cond(T, A, B, h):
    h_new = [0 for i in range(len(h))]
    for i in range(len(h)):
        h_new[i] = h[i] - B*T

    s = 0
    for i in range(len(h)):
        if h_new[i] > 0:
            s += h_new[i] / (A - B) + (0 if h_new[i] % (A - B) == 0 else 1)

    return s <= T

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, A, B] = [long(input_raw[0]), long(input_raw[1]), long(input_raw[2])]
    h = []
    for i in range(N):
        input_raw = read_func().strip().split()
        h.append(long(input_raw[0]))
    
    l = 0L
    r = max(h)/B + 1
    while(1):
        #print l r
        if abs(l - r) <= 1:
            print r
            break
        T = (l + r)/2
        if is_cond(T, A, B, h) == True:
            r = T
        else:
            l = T


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
a,b,c = map(int,input().split(" "))
ar = []
count = 0
for i in range(a):
    l = int(input())
    ar.append(l)
while max(ar) > 0:
    n = ar.index(max(ar))
    for j in range(a):
        if j == n:
            ar[j] -= b
        else:
            ar[j] -= c
    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 = int(input())
    H.append(h)


def enough(T):
    num = 0
    for i in range(N):
        if H[i] - B * T > 0:
            num += (H[i] - B * T) // (A - B)
            num += int((H[i] - B * T) % (A - B) != 0)
    return T >= num


left, right = 0, 10 ** 9 + 1
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    if enough(mid):
        right = mid
    else:
        left = mid

print(right)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
h = list(int(input()) for i in range(n))
h.sort(reverse=True)
cnt = 0
while h[0]>0:
    cnt +=1
    h[0] -= a
    for i in range(1,n):
        h[i] -= b
    h.sort(reverse=True)

print(cnt)

Submission status: Time Limit Exceeded

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

count = 0
while True:
	if np.max(h) <= 0:
		break
	idx = np.argmax(h)
	h = h - B
	h[idx] = h[idx] - A + B
	count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
import math

def f(h, a, b, t):
    y = 0
    for hi in h:
        if hi-b*t <= 0:
            break
        else:
            y += math.ceil((hi-b*t)/(a-b))
    if y <= t:
        return True
    else:
        return False

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

low = 1
high = math.ceil(h[0]/b)

while True:
    m = (low+high)//2
    if f(h,a,b,m):
        high = m
    else:
        low = m
    if low +1 == high:
        break

print(high)

Submission status: Time Limit Exceeded

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

left = 0
right = 10**10
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    count = 0
    for i in range(n):
        if h[i] - mid * b > 0:
            if (h[i] - mid * b) % (a - b) == 0:
                count += (h[i] - mid * b) // (a - b)
            else:
                count += (h[i] - mid * b) // (a - b) + 1
    if mid - count >= 0:
        right = mid
    else:
        left = mid
print(right)

Submission status: Time Limit Exceeded

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

left = 0
right = 10**9
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    count = 0
    for i in range(n):
        if h[i] - mid * b > 0:
            if (h[i] - mid * b) % (a - b) == 0:
                count += (h[i] - mid * b) // (a - b)
            else:
                count += (h[i] - mid * b) // (a - b) + 1
    if mid - count >= 0:
        right = mid
    else:
        left = mid
print(right)

Submission status: Time Limit Exceeded

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

left = 0
right = 10**12
mid = (left + right) // 2
while right - left > 1:
    mid = (left + right) // 2
    count = 0
    for i in range(n):
        if h[i] - mid * b > 0:
            if (h[i] - mid * b) % (a - b) == 0:
                count += (h[i] - mid * b) // (a - b)
            else:
                count += (h[i] - mid * b) // (a - b) + 1
    if mid - count >= 0:
        right = mid
    else:
        left = mid
print(right)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

heapq.heapify(h)
count = 0
while True:
    count += 1
    ele = -heapq.heappop(h)
    ele -= (a - b)
    heapq.heappush(h, -ele)
    ele = -heapq.heappop(h)
    if ele <= b * count:
        print(count)
        break
    heapq.heappush(h, -ele)

Submission status: Time Limit Exceeded

Solution code:
import heapq

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

heapq.heapify(h)
count = 0
while True:
    count += 1
    ele = -heapq.heappop(h)
    ele -= (a - b)
    heapq.heappush(h, -ele)
    ele = -heapq.heappop(h)
    if ele <= b * count:
        print(count)
        break
    heapq.heappush(h, -ele)

Submission status: Time Limit Exceeded

Solution code:
def main13():
    buf = input("");
    bufs = buf.split();
    hai = [];
    result = 0;
    for i in range(len(bufs)):
        hai.append(int(bufs[i]));
    mamono = [];
    for i in range(hai[0]):
        mamono.append(int(input("")));
    while(True):
        moku = mamono.index(max(mamono));
        lenn = len(mamono);
        for i in range(lenn):
            if i == moku:
                mamono[i] = mamono[i] - hai[1];
            else:
                mamono[i] = mamono[i] - hai[2];
        for i in range(lenn):
            if mamono[(lenn - (i + 1))] < 1:
                del(mamono[(lenn - (i + 1))]);
        result = result + 1;
        if len(mamono) == 0:
            break;
    print(result);



if __name__ == '__main__':
    main13()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
N, A, B = map(int, raw_input().split())
h = [0] * N
for i in range(N):
  h[i], = map(int, raw_input().split())
h.sort()

l = 0
r = int(ceil(1.0*h[-1]/B))
while True:
  m = (l+r)//2
  if m==l:
    break
  c = 0
  for i in range(N):
    ai = int(ceil(1.0*max(0,h[i]-B*m)/(A-B)))
    c += ai
  if c>m:
    l = m
  else:
    r = m
print r

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,a,b = map(int,raw_input().split())

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

def enough(n):
	t = n
	for i in arr:
		t -= np.ceil((i - n*b*1.0) / (a-b))

	return False if t < 0 else True

l = 0
r = 10**9

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

print r

Submission status: Time Limit Exceeded

Solution code:
import sys,math

N,A,B=map(int,input().split())
H = [0] * N
H = [int(input()) for i in range(N)]
 
maxH = max(H)
L=-1
R=math.ceil(maxH / B)

while R-L>1:
    MID=(L+R)//2
    SUM=0
    for i in range(N):
        SUM+=max(0,math.ceil(max(H[i]-B*MID,0)/(A-B)))

    if SUM>MID:
        L=MID
    else:
        R=MID

print(R)

Submission status: Time Limit Exceeded

Solution code:
import sys,math

N,A,B=map(int,input().split())
H = [0] * N
H = [int(input()) for i in range(N)]
 
maxH = max(H)
L=-1
R=math.ceil(maxH / B)

while R-L>1:
    MID=int((L+R)/2)
    SUM=0
    for i in range(N):
        Q=float(float(H[i])-float(MID*B)+float(A-B-1))//float(A-B)
        SUM+=max(0,int(Q))

    if SUM>MID:
        L=MID
    else:
        R=MID

print(R)

Submission status: Time Limit Exceeded

Solution code:
import sys,math

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

L=-1
R=sys.maxsize

def binary_search(D,U):
    MID=(D+U)//2
    if(MID==D):
        print(U)
    else:
        if sum(math.ceil(max(h-B*MID,0)/(A-B))for h in H)<=MID:
            binary_search(D,MID)
        else:
            binary_search(MID,U)


binary_search(L,R)

Submission status: Time Limit Exceeded

Solution code:
import sys

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

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

L=-1
R=sys.maxsize

while R-L>1:
    MID=int((L+R)/2)
    SUM=0
    for i in range(N):
        Q=float(float(H[i])-float(MID*B)+float(A-B-1))//float(A-B)
        SUM+=max(0,int(Q))

    if SUM>MID:
        L=MID
    else:
        R=MID

print(R)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int,input().split())
h = [0 for i in range(N)]
for i in range(N):
	h[i] = int(input())
h = sorted(h)
import math
# N, A, B = 4, 5, 3
# h = [8,7,4,2]
# h = sorted(h,reverse=True)

def enough(T):
	tmp = 0
	for i in range(N):
		if h[i] >= B*T:
			tmp += math.ceil((h[i]-B*T)/(A-B))
	return True if tmp <= T else False

MAX = 10**9
MIN = 0
while MAX > MIN:
	if enough(MAX) == True and enough(MIN) == False and MAX - MIN == 1:
		break
	MID = (MAX+MIN)//2
	if enough(MID) == True:
		if enough(MID-1) == True:
			MAX = MID-1
		else:
			MAX = MID
	else:
		if enough(MID+1) == False:
			MIN = MID+1
		else:
			MIN = MID
print(MAX)

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b=[int(i) for i in input().split()]
ab=a-b
t=[int(input()) for i in range(n)]
mx = sum([i//a +1 for i in t])
mi = 1

while mx - mi > 1:
  i = (mx + mi) // 2
    
  ti= [j- i * b for j in t]
  if sum([max(math.ceil(j/ab),0) for j in ti]) <= i:
    mx = i
  else:
    mi = i
  
print(mx)

Submission status: Time Limit Exceeded

Solution code:
import math
n, a, b=[int(i) for i in input().split()]
ab=a-b
t=[int(input()) for i in range(n)]
mx = max(t)//b + 1
mi = 1

while mx-mi>=1:    
  i = (mx + mi) // 2
    
  ti= [j- i * b for j in t]
  if sum([max(math.ceil(j/ab),0) for j in ti]) <= i:
    mx=i
  else:
    mi=i
print(mx)

Submission status: Time Limit Exceeded

Solution code:
import numpy
N, A, B = map(int, input().split(' '))
monsters = numpy.array([int(input()) for _ in range(N)])
count = 0
while numpy.any(monsters > 0):  
    max_hp_index = numpy.argmax(monsters)
    monsters -= B
    monsters[max_hp_index] -= (A - B)
    count += 1
print(count)

Submission status: Time Limit Exceeded

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

from math import ceil

def can_korosu(t):
    count = 0
    for h in H:
        count += ceil(max(0, h - t*B)/(A-B))
        if count > t:
            return False
    return True

lo = 0
hi = 10**9

for _ in range(50):
    mid = (hi + lo) // 2
    if can_korosu(mid):
        hi = mid
    else:
        lo = mid
print(hi)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, input().split())
h = [int(input()) for i in range(N)]
Tmax=2*max(h)//B
def Tenabled(Tin):
    x = [h[i] for i in range(N)]
    for i in range(N):
        x[i] -= B*Tin
    S = 0
    for i in range(N):
        if x[i]>0:
            S += -((-x[i])//(A-B))
    if S<=Tin:
        return True
    else:
        return False


high=Tmax
low=0
t=(high+low)//2
while(low<=high):
    if Tenabled(t):
        high=t
    else:
        low=t+1
    t=(high+low)//2
    if Tenabled(t)==True and Tenabled(t-1)==False:
        break
print(t)

Submission status: Time Limit Exceeded

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

    TLE(N, A, B, hs)


def TLE(N, A, B, hs):
    answer = 0
    max_hp = max(hs)
    while max_hp > 0:
        idx_max = -1
        for i, hp in enumerate(hs):
            if hp <= 0:
                continue
            if idx_max == -1 and max_hp == hp:
                hs[i] -= A
                idx_max = i
            else:
                hs[i] -= B
        max_hp = max(hs)
        answer += 1

    print(answer)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
import pdb

def main():
    '''
    N: number of monsters
    A: point blank
    B: spread damage
    '''
    [N, A, B] = map(int, raw_input().split(' '))
    HPs = np.zeros(N)
    for k in range(N):
        HPs[k] = int(raw_input())

    answer = strategy(HPs, A, B)
    print answer

def strategy(HPs, A, B):
    turn = 0
    while max(HPs) > 0:
        HPs = np.sort(HPs)[::-1]
        HPs[0]= HPs[0] - (A - B)
        HPs = HPs - B
        turn += 1
    return turn


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

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


def max_and_argmax(array):
    max_value = max(array)
    return max_value, array.index(max_value)


def attack(target_index, h_list, N, A, B):
    max_value = -1
    max_index = 0
    for i in range(N):
        if i == target_index:
            h_list[i] -= A
        else:
            h_list[i] -= B
        if max_value < h_list[i]:
            max_value = h_list[i]
            max_index = i
    return max_value, max_index

max_value, max_index = max_and_argmax(h_list)
count = 0
while max_value > 0:
    max_value, max_index = attack(max_index, h_list, N, A, B)
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

# print(N, A, B)
# print(h_list)


def argmax(array):
    max_value = max(array)
    return array.index(max_value)


def attack(target_index, h_list, N, A, B):
    for i in range(N):
        if i == target_index:
            h_list[i] -= A
        else:
            h_list[i] -= B

count = 0
while True:
    if max(h_list) <= 0:
        break
    attack(argmax(h_list), h_list, N, A, B)
    count += 1

print(count)

Submission status: Time Limit Exceeded

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

# print(N, A, B)
# print(h_list)


def argmax(array):
    max_value = max(array)
    return array.index(max_value)


def attack(target_index, h_list, N, A, B):
    damages = [B for i in range(N)]
    damages[target_index] = A
    for i in range(N):
        h_list[i] -= damages[i]

count = 0
while True:
    if max(h_list) <= 0:
        break
    attack(argmax(h_list), h_list, N, A, B)
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
def enough(t, hp, a, b):
    need = 0
    for x in hp:
        m = (x - (b * t))/(a - b)
        if((m != int(m)) and (m > 0)):
            need += int(m + 1)
        if((m == int(m)) and (m > 0)):
            need += int(m)

    if(need <= t):
        return True
    else:
        return False

idx = list(map(int, input().split()))
hp = []

for i in range(idx[0]):
    hp.append(int(input()))

low = 1
high = max(hp)
t = (low + high) // 2

while(low < high):
    if(enough(t, hp, idx[1], idx[2])):
        high = t
    else:
        low = t + 1
        
    t = (low + high) // 2

print(t)

Submission status: Time Limit Exceeded

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

high=max(h)
low=1

def enough(T):
	h2=copy.deepcopy(h)
	cnt=0
	for i in range(N):
		h2[i]-=T*B
		if h2[i]>0:
			if h2[i]%(A-B)==0:
				cnt+=h2[i]/(A-B)
			else:
				cnt+=h2[i]/(A-B)+1
	if cnt<=T:
		return True
	else:
		return False

ans=0
while low<=high:
	c= (low + high) / 2
	if enough(c):
		high=c-1
		ans=c
	else:
		low=c+1


print ans

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,raw_input().split())
h = []
for i in range(n):
	x = int(input())
	h.append(x)
c = 0
while max(h) > 0:
	c += 1
	h[h.index(max(h))] -= a-b
	h = list(map(lambda x: x-b,h))
print c

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
"""
http://abc063.contest.atcoder.jp/tasks/arc075_b
TLE
"""
import sys
from sys import stdin
from math import ceil
input = stdin.readline


def Cond(monsters, A, B, mid):
    t = [x - (B * mid) for x in monsters]
    t.sort(reverse=True)
    additional_damage = (A - B)

    total_count = 0
    for m in t:
        if m < 1:
            break
        total_count += ceil(m / additional_damage)

    if total_count <= mid:
        return True
    else:
        return False


def main(args):
    # N = 2
    # A = 10
    # B = 4
    # monsters = [20, 20]
    N, A, B = map(int, input().split())
    monsters = [int(input()) for _ in range(N)]

    total_count = 0
    if N == 1:
        total_count = ceil(monsters[0] / A)
    else:
        monsters.sort(reverse=True)
        lb = ceil(monsters[0] / A)
        ub = ceil(monsters[0] / B)
        # lb = 0
        # ub = 1e10

        for _ in range(100):
            mid = (lb + ub) // 2
            if Cond(monsters, A, B, mid):
                ub = mid
            else:
                lb = mid
        total_count = int(ub)

    print(total_count)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Time Limit Exceeded

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

import heapq
heapq.heapify(h)

thre = 0
ans = 0
while True:
    h_target = heapq.heappop(h)
    if h_target >= thre:
        break

    heapq.heappush(h, h_target + (A - B))
    thre -= B
    ans += 1

print(ans)