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:
n, a, b = [int(i) for i in input().split()]
hs = [None]*n
kill_b = [None]*n
all_hp = 0
all_killb = 0
for i in range(n):
    hs[i] = int(input())
    # all_hp += hs[i]
    # kill_b[i] = hs[i] // b
    # if((hs[i] % b) != 0):
    #     kill_b[i] += 1
    # all_killb += kill_b[i]
# hs.sort()
max_hp = max(hs)
ret = 0
if(a == b):
    ret = max_hp // a
    if((max_hp % a) != 0):
        ret += 1
    else:
        pass
else:
    ab = a - b
    right = max_hp // b
    if((max_hp % b) == 0):
        right += 1
    left = 1
    while right != left:
        middle = (right + left) // 2
        print([left, right, middle])
        all_a = 0
        for x in hs:
            nokori = x - (b * middle)
            if(nokori > 0):
                num_a = nokori // ab
                if(x > num_a * a + (middle - num_a) * b):
                    num_a += 1
                all_a += num_a
        if(all_a <= middle):
            right = middle
        else:
            left = middle + 1
    ret = right
    # for i in range(hs[-1] // b):
        # flag = False
        # for j in range(n):
        #     ret += 1
        #     base_height = (ret * b) + (i * (a-b))
        #     #print(base_height)
        #     if((j == n-1) or (hs[-(j+2)] <= (base_height))):
        #         break
        # max_height = (ret * b) + ((i + 1) * (a-b))
        # if(max_height >= hs[-1]):
        #     break
print(ret)

Submission status: Wrong Answer

Solution code:
import math

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

m = sum(hs) // (a + (n-1)*b)
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Submission status: Wrong Answer

Solution code:
import math

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

m = 0
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b)) / (a-b)) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Submission status: Wrong Answer

Solution code:
import math

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

m = 0
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(math.ceil((h-p*b) / (a-b)) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Submission status: Wrong Answer

Solution code:
import math

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

m = math.floor(sum(hs) / (a+(n-1)*b)) - 100
M = sum(math.ceil(h/a) for h in hs) + 100

def killable(p, hs, a, b):
    x = sum(math.ceil((h-p*b) / (a-b)) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Submission status: Wrong Answer

Solution code:
import math

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

m = math.floor(sum(hs) / (a+(n-1)*b)) - 1
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(math.ceil((h-p*b) / (a-b)) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Submission status: Wrong Answer

Solution code:
import math

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

h = []
min_h = 10 ** 10
max_h = 0
for _ in range(N):
    hi = int(input())
    if hi < min_h:
        min_h = hi
    if hi > max_h:
        max_h = hi
    h.append(hi)
    
min_K = math.ceil(min_h / A)
max_K = math.ceil(max_h / B)
K = min_K
while(min_K != max_K):
    x = [math.ceil((n - K * B) / (A - B)) for n in h]
    #sum_x = sum([xi for xi in x if xi > 0])
    sum_x = sum(x)
    if sum_x <= K:
        max_K = K
        K = math.floor((min_K + K) / 2)
    else:
        min_K = K + 1
        K = math.floor((K + max_K) / 2) + 1

print(min_K)

Submission status: Wrong Answer

Solution code:
import math

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

h = []
for _ in range(N):
    h.append(int(input()))
    
min_K = math.ceil(sum(h) / (A - B + B * N)) - 1
max_K = math.ceil(max(h) / A) * N
K = max_K
while(min_K != max_K):
    x = [math.ceil((n - K * B) / (A - B)) for n in h]
    sum_x = sum([xi for xi in x if xi > 0])
    if sum_x <= K:
        max_K = K
        K = int((min_K + K) / 2)
    else:
        K = int((K + max_K) / 2) + 1
        min_K = K

print(K)

Submission status: Wrong Answer

Solution code:
import math

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

h = []
for _ in range(N):
    h.append(int(input()))
    
min_K = math.ceil(sum(h) / (A - B + B * N)) - 1
max_K = math.ceil(max(h) / A) * N
x = []
K = max_K
while(min_K != max_K):
    sum_x = 0
    for i, n in enumerate(h):
        sum_x += math.ceil((n - K * B) / (A - B))
    if sum_x <= K:
        max_K = K
        K = math.floor((min_K + K) / 2)
        if K == min_K:
            K += 1
            break
    else:
        min_K = K
        K = math.ceil((K + max_K) / 2)

print(K)

Submission status: Wrong Answer

Solution code:
import math


def rren(): return list(map(int, input().split()))


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


left = 0
right = math.ceil(max(h)/B)
while(left <= right):
    K = math.floor((left + right) / 2)
    if(K == left):
        print(K)
        break
    else:
        sum = 0
        for i in range(N):
            foo = max(0, math.ceil((h[i] - K*B)/(A-B)))
            sum += foo
        if(sum <= K):
            right = K
        else:
            left = K+1

Submission status: Wrong Answer

Solution code:
import math

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

h = []
for _ in range(N):
    h.append(int(input()))
    
sum_h = sum(h)
min_count = math.ceil(sum_h / (A - B + B * N))
for i, n in enumerate(h):
    h[i] -= min_count * B

diff_damage = A - B
plus_count = 0
for n in h:
    if n > 0:
        plus_count += math.ceil(n / diff_damage)

if min_count > plus_count:
    print(min_count)
else:
    print(plus_count)

Submission status: Wrong Answer

Solution code:
import heapq
from collections import Counter
import math

n, a, b = map(int, input().split())
hs = map(int, (input() for _ in range(n)))
counter = [[-x, c] for x, c in Counter(hs).items()]

cum = 0
p = 0

heapq.heapify(counter)

def f(m, c, a, b):
    ans = 0
    ans += math.floor(m / (a + b*(c-1))) * c
    m -= math.floor(m / (a + b*(c-1))) * (a + b*(c-1))
    ans += min(math.ceil(m / b), math.ceil(m / (a + b*(c-1)))*c)
    return ans

while(True):
    x, y = heapq.heappop(counter)
    if len(counter) == 0:
        print(p + f(-x-cum, y, a, b))
        break
    v, _ = counter[0]
    if x==v:
        counter[0][1] += y
        continue
    m = math.ceil((v-x) / (a-b))
    if (-x) - (m*a + m*(y-1)*b + cum) <= 0 and (-v) - m*y*b <=0:
        print(p + f(-x-cum, y, a, b))
        break
    p += m*y
    cum += b*m*y
    heapq.heappush(counter, [x + m*(a-b), y])

Submission status: Wrong Answer

Solution code:
import math

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

h = []
for _ in range(N):
    h.append(int(input()))
    
sum_h = sum(h)
min_count = math.ceil(sum_h / (A - B + B * N))
for i, n in enumerate(h):
    h[i] -= min_count * B

diff_damage = A - B
plus_count = 0
for n in h:
    if n > 0:
        plus_count += math.ceil(n / diff_damage)

print(plus_count)

Submission status: Wrong Answer

Solution code:
import heapq
from collections import Counter
import math

n, a, b = map(int, input().split())
hs = map(int, (input() for _ in range(n)))
counter = [[-x, c] for x, c in Counter(hs).items()]

cum = 0
p = 0

heapq.heapify(counter)

def f(m, c, a, b):
    ans = 0
    ans += math.floor(m / (a + b*(c-1))) * c
    m -= math.floor(m / (a + b*(c-1))) * (a + b*(c-1))
    ans += min(math.ceil(m / b), math.ceil(m / (a + b*(c-1)))*c)
    return ans

while(True):
    x, y = heapq.heappop(counter)
    if len(counter) == 0:
        print(p + f(-x-cum, y, a, b))
        break
    v, _ = counter[0]
    m = math.ceil((v-x) / (a-b))
    if (-x) - (m*a + m*(y-1)*b + cum) <= 0 and (-v) - m*y*b <=0:
        print(p + f(-x-cum, y, a, b))
        break
    p += m*y
    cum += b*m*y
    if x+m*(a-b) == v:
        counter[0][1] += y
    else:
        heapq.heappush(counter, [x + m*(a-b), y])

Submission status: Wrong Answer

Solution code:
n,a,b = map(int, raw_input().split())
hn = []
for _ in range(n):
  hn.append(int(raw_input()))

s = sum(hn)
if s % ((n-1)*b+a) > 0:
  print s / ((n-1)*b+a) + 1
else:
  print s / ((n-1)*b+a)

Submission status: Wrong Answer

Solution code:
# D
import numpy as np
N, A, B = map(int, input().split())
H = []
for _ in range(N):
    H.append(int(input()))
    
H_sorted = np.sort(np.array(H))[::-1]

HP_ALL = H_sorted.sum()

H_list = list(H_sorted)

N_alive = N

# find when damege_ALL > HP_ALL
# if all alive
while True:
    N_attack = HP_ALL // (A + (N_alive-1)*B)
    # some are dead before it
    for i in range(N_alive-1, -1, -1):
        if H_sorted[i] <= B * N_attack:
            HP_ALL -= H_sorted[i]
        else:
            N_alive_ = i + 1
            break
            
    if N_alive == N_alive_:
        break
    else:
        N_alive = N_alive_

                                            
print(int(np.ceil(HP_ALL / (A + (N_alive-1)*B))))

Submission status: Wrong Answer

Solution code:
import heapq
from collections import Counter
import math

n, a, b = map(int, input().split())
hs = map(int, (input() for _ in range(n)))
counter = [[-x, c] for x, c in Counter(hs).items()]

cum = 0
p = 0

heapq.heapify(counter)

def f(m, c, a, b):
    ans = 0
    ans += math.floor(m / (a + b*(c-1))) * c
    m -= math.floor(m / (a + b*(c-1))) * (a + b*(c-1))
    ans += min(math.ceil(m / b), math.ceil(m / (a + b*(c-1)))*c)
    return ans

while(True):
    x, y = heapq.heappop(counter)
    if len(counter) == 0:
        print(p + f(-x-cum, y, a, b))
        break
    v, _ = counter[0]
    m = math.ceil((v-x) / (a-b))
    if (-x) - (m*a + m*(y-1)*b + cum) <= 0:
        print(p + f(-x-cum, y, a, b))
        break
    p += m*y
    cum += b*m*y
    if x+m*(a-b) == v:
        counter[0][1] += y
    else:
        heapq.heappush(counter, [x + m*(a-b), y])

Submission status: Wrong Answer

Solution code:
import math
N,A,B = map(int,input().split())
H = [int(input()) for i in range(N)]
Hs = sum(H)
c = A - B
M = math.ceil(Hs / B)

m = math.ceil(Hs / (A * N))

while M - m > 1:
	n = (M + m) // 2
	H2 = [H[i] - n * B for i in range(N) if H[i] - n * B > 0]
	cnts = [math.ceil(H2[i] / c) for i in range(len(H2))]
	cnt = sum(cnts)
	if cnt > n:
		m = n
	elif cnt == n:
		M = n
		break
	else:
		M = n
print(M)

Submission status: Wrong Answer

Solution code:
import math
N,A,B = map(int,input().split())
H = [int(input()) for i in range(N)]
Hs = sum(H)
c = A - B
M = math.ceil(Hs / (B * N))

m = math.ceil(Hs / (A * N))

nibun = [M,m]
while M - m > 1:
	n = (M + m) // 2
	H2 = [H[i] - n * B for i in range(N) if H[i] - n * B > 0]
	cnts = [math.ceil(H2[i] / c) for i in range(len(H2))]
	cnt = sum(cnts)
	if cnt > n:
		m = n
	elif cnt == n:
		M = n
		break
	else:
		M = n
print(M)

Submission status: Wrong Answer

Solution code:
import math
N,A,B = map(int,input().split())
H = [int(input()) for i in range(N)]
Hs = sum(H)
c = A - B
M = math.ceil(Hs / (B * N))

m = math.ceil(Hs / (A * N))

nibun = [M,m]
while M - m > 1:
	n = (M + m) // 2
	H2 = [H[i] - n * B for i in range(N) if H[i] - n * B > 0]
	cnts = [math.ceil(H2[i] / c) for i in range(len(H2))]
	cnt = sum(cnts)
	if cnt > n:
		m = n
	else:
		M = n
print(m)

Submission status: Wrong Answer

Solution code:
import math
N,A,B = map(int,input().split())
H = [int(input()) for i in range(N)]
Hs = sum(H)
c = A - B
M = math.ceil(Hs / (B * N))

m = math.ceil(Hs / (A * N))

nibun = [M,m]
while M - m > 1:
	n = (M + m) // 2
	H2 = [H[i] - n * B for i in range(N) if H[i] - n * B > 0]
	cnts = [math.ceil(H2[i] / c) for i in range(len(H2))]
	cnt = sum(cnts)
	if cnt > n:
		m = n
	else:
		M = n
print(M)

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, raw_input().split())
H = [int(raw_input()) for i in xrange(n)]

left = 1; right = 10**9+1
while left+1 < right:
    mid = (left + right) / 2
    cnt = 0
    for h in H:
        h -= mid * b
        cnt += (h + a-b - 1) / (a-b)
    if mid <= cnt:
        left = mid
    else:
        right = mid
print right

Submission status: Wrong Answer

Solution code:
n, a, b = map(int, raw_input().split())
H = [int(raw_input()) for i in xrange(n)]

left = 1; right = 10**9+1
while left+1 < right:
    mid = (left + right) / 2
    cnt = 0
    for h in H:
        h -= mid * b
        cnt += (h + a-b - 1) / (a-b)
    if mid < cnt:
        left = mid
    else:
        right = mid
print right

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
from collections import deque
def getN():
    return int(input())
def getList():
    return list(map(int, input().split()))
import math
import copy
from collections import deque

class SegTree():
    def __init__(self, n):
        self.value = [0 for i in range(n*2)]

MOD = 10 ** 9 + 7

def getinvmod(n):
    return [pow(i, MOD-2, MOD) for i in range(n+1)]

def judge(monsterss, n_attack, a, b):
    monsters = copy.copy(monsterss)
    attack = 0
    for monster in monsters:
        # monster -= n_attack * b
        if monster > 0:
            attack += math.ceil(max(0, (monster - b*n_attack)/(a-b)))

    return attack <= n_attack


def main():
    n, a, b = getList()
    monsters = []
    for i in range(n):
        monsters.append(getN())

    mn = 0
    mx = 10 ** 15
    while(mx - mn > 1):
        mid = (mn + mx) // 2
        if judge(monsters, mid, a, b):
            mx = mid
        else:
            mn = mid

    if judge(monsters, mn, a, b):
        print(mn)
    else:
        print(mx)



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


def judge(k: int, h: list, a:int, b:int):
    h = [max(0, hi - k*b) for hi in h]
    cnt = 0
    for hi in h:
        cnt += -(-hi//(a-b))

    return True if cnt <= k else False

def binary_search(h, a, b):
    low = 0
    high = 10**18

    while high - low > 1:
        mid = (high+low) // 2
        if judge(mid, h, a, b):
            high = mid
        else:
            low = mid

    return high

n, a, b = li()
h = [ni() for _ in range(n)]

print(binary_search(h, a, b))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

def jugde(n):
    count = 0
    for i in range(N):
        count+=max(np.ceil((h[i]-B*n)/(A-B)),0)
    if count<=n:
        return True
    else:
        return False

def bisect(i,j):
    if j-i==1:
        return j
    else:
        if jugde((i+j)//2):
            return bisect(i,(i+j)//2)
        else:
            return bisect((i+j)//2,j)

print(bisect(0,10**9))

Submission status: Time Limit Exceeded

Solution code:
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def ceil(x):
    return int((-x)//1*(-1))


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


def solve1():
    HP = sorted(hp, reverse=True)
    cnt = 0
    while HP:
        HP = list(map(lambda x: x-B, HP))
        HP[0] -= A-B
        HP = list(filter(lambda x: x > 0, HP))
        HP = sorted(HP, reverse=True)
        cnt += 1
        print(HP)
    print(cnt)


def check(x, HP):
    cnt = 0
    for i in range(N):
        if HP[i]-B*x <= 0:
            break
        else:
            cnt += ceil((HP[i]-B*x)/diff)
    #print("x->", x)
    # print(cnt)
    #print(cnt <= x)
    return cnt <= x


def solve2():
    HP = sorted(hp, reverse=True)
    mi = HP[0]//A
    ma = ceil(HP[0]/B)
    #print("mi,ma->", mi, ma)
    while mi <= ma:
        mid = (mi+ma)//2
        if check(mid, HP):
            ma = mid-1
        else:
            mi = mid+1
    print(mi)


solve2()

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ((h[i]-val*b-1)/(a-b))+1
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,10**9
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ceil((h[i]-val*b)/float(a-b))
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,max(h)+10
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Submission status: Time Limit Exceeded

Solution code:
from math import ceil
def solve(val):
	z = 0
	for i in range(n):
		if h[i] <= val*b:
			pass
		else:
			z += ceil((h[i]-val*b)/float(a-b))
	if z <= val:
		return True
	else:
		return False
n,a,b = map(int,raw_input().split())
h = [input() for i in range(n)]
lo,hi = 1,10**12
while lo < hi:
	mid = lo+(hi-lo)//2
	if solve(mid):
		hi = mid
	else:
		lo = mid+1
print lo

Submission status: Time Limit Exceeded

Solution code:
a,b,c = map(int,input().split(" "))
count = 0
ar = []
for i in range(a):
    l = int(input())
    ar.append(l)
while True:
    d = 0
    ar.sort()
    ar = [r - c for r in ar]
    ar[len(ar)-1] -= b - c
    count += 1
    for r in ar:
        if r <= 0:
            d += 1
    if d == a:
        print(count)
        exit()

Submission status: Time Limit Exceeded

Solution code:
def inpl(): return [int(i) for i in input().split()]

N,A,B = inpl()
C = A-B
h = [int(input()) for _ in range(N)]

ans = -(-sum(h)//((N-1)*B+A))
while True:
    hprime = [h[i]-ans*B for i in range(N) if h[i]-ans*B >0]
    hans = ans    
    for j in hprime:
            hans -= -(-j//C)
    if hans >= 0:
        break
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]
h.sort()
p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**17
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)

Submission status: Time Limit Exceeded

Solution code:
import heapq
n,a,b= map(int,input().split())
h =[int(input()) for i in range(n)]
h.sort()
p = a-b
def c(w):
    #w de umakuikkuka
    k = 0
    for i in range(n):
        l[i] = l[i]-b*w
        if l[i] > 0:
            k += l[i]//p
            if l[i] % p != 0:
                k += 1
    if w >= k:
        return True

s = 0
f = 10**18
while f-s >=2:
    m = (f+s)//2
    l = h[::]
    if c(m):
        f = m
    else:
        s = m
l = h[::]
if c(s):
    print(s)
else:
    print(f)

Submission status: Time Limit Exceeded

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

tekis = list(sorted(teki))

while tekis != []:
    tekis[-1] = tekis[-1] - a
    if len(tekis) >= 2:
        for i in range(len(tekis) -1):
            tekis[i] = tekis[i] - b
    tekis = list(sorted(tekis))
    for i in range(len(tekis)):
        if tekis[i] <= 0:
            tekis[i] = 0
    while 0 in tekis:
        tekis.remove(0)
    ans += 1
print(ans)

Submission status: Time Limit Exceeded

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

minimum = (min(pre_h) - 1) // a + 1

h = [0] * n
while True:
	for i in range(n):
		if pre_h[i] - b * minimum > 0:
			h[i] = pre_h[i] - b * minimum
		else:
			h[i] = 0

	if sum([(i - 1) // (a - b) + 1 for i in h]) <= minimum:
		break

	#print(h)
	minimum += 1

print(minimum)

Submission status: Time Limit Exceeded

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

def enough(T):
    global h
    c = 0
    h2 = h - b * T
    for i, f in enumerate(h2 > 0):
        if not f:continue
        c += ceil(h2[i]/(a - b))
    if c <= T: return 1
    else: return 0

def bisearch():
    lo = 0
    hi = ceil(max(h)/b)
    while lo < hi:
        mid = (lo + hi) // 2
        midval = enough(mid)
        if midval < 1: lo = mid + 1
        else: hi = mid
    return lo

print(bisearch())

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect
def inpl(): return tuple(map(int, input().split()))

N, A, B = inpl()
D = A-B
H = []
res = 0
for _ in range(N):
    H.append(int(input()))

x = sum(H) // (A+B*(N-1))
H = sorted(H)
 
while len(H):
    nH = [h - B*x for h in H]
    i = bisect(nH, 0)
    nH = nH[i:]
    H = H[i:]
    if sum([h//D + (h%D>0) for h in nH]) <= x:
        print(x)
        break
    else:
        x = max(x+1, sum(H) // (A+B*(N-1)))

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from bisect import bisect
def inpl(): return tuple(map(int, input().split()))

N, A, B = inpl()
D = A-B
H = []
res = 0
for _ in range(N):
    H.append(int(input()))

x = sum(H) // (A+B*(N-1))
H = sorted(H)
 
while len(H):
    nH = [h - B*x for h in H]
    i = bisect(nH, 0)
    nH = nH[i:]
    H = H[i:]
    if sum([h//D + (h%D>0) for h in nH]) <= x:
        print(x)
        break
    else:
        x += 1

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
from numpy import array, int64
from bisect import bisect
def inpl(): return tuple(map(int, input().split()))

N, A, B = inpl()
D = A-B
H = []
res = 0
for _ in range(N):
    H.append(int(input()))

x = sum(H) // (A+B*(N-1))
H = array(sorted(H)).astype(int64)
 
while len(H):
    nH = H - B*x
    i = bisect(nH, 0)
    nH = nH[i:]
    H = H[i:]
    if sum(nH//D + (H%D>0)) <= x:
        print(x)
        break
    else:
        x += 1

Submission status: Time Limit Exceeded

Solution code:
#!usr/bim/python
#! -*- coding: utf-8 -*-

import numpy as np

nab = raw_input()
nab = nab.split()
n,a,b = map(int,nab)

h = np.zeros(n, dtype=np.int32)
for i in range(n):
    hp = raw_input()
    hp = int(hp)
    h[i] = hp

o = a - b

i = 0
while max(h) > 0:
    h -= b
    h[np.argmax(h)] -= o
    i += 1

print i

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def widespread_2():
	n, a, b = map(int, raw_input().split(" "))
	monsters = []
	for i in range(n):
		monsters.append(int(raw_input()))
	# as a>b holds
	dif_a_b = a - b
	monsters = np.array(monsters)
	max_ans = int(max(monsters)/b)+1
	min_ans = int(max(monsters)/a)-1
	# using binary search
	while True:
		current_attepmt = int((max_ans+min_ans)/2)
		# print current_attepmt
		re = _inner_widespread_2(monsters, current_attepmt, a, b)
		# print re
		if re>current_attepmt:
			min_ans = current_attepmt
		elif re<current_attepmt:
			max_ans = current_attepmt
		else:
			print current_attepmt
			return

		if current_attepmt==int((max_ans+min_ans)/2):
			print max_ans
			return


def _inner_widespread_2(monsters, attemps, a, b):
	dif = a-b
	re = 0
	for e in monsters:
		update_e = e-b*attemps
		if update_e>0:
			if update_e%dif==0:
				re = re+update_e/dif
			else:
				re = re + int(update_e/dif)+1
	return re


if __name__ == "__main__":
	widespread_2()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

def widespread_2():
	n, a, b = map(int, raw_input().split(" "))
	monsters = []
	for i in range(n):
		monsters.append(int(raw_input()))
	# as a>b holds
	dif_a_b = a - b
	monsters = np.array(monsters)
	max_ans = int(max(monsters)/b)+1
	min_ans = int(max(monsters)/a)-1
	# using binary search
	while True:
		current_attepmt = int((max_ans+min_ans)/2)
		# print current_attepmt
		re = _inner_widespread_2(monsters, current_attepmt, a, b)
		# print re
		if re>current_attepmt:
			min_ans = current_attepmt
		elif re<current_attepmt:
			max_ans = current_attepmt
		else:
			print current_attepmt
			return

		if current_attepmt==int((max_ans+min_ans)/2):
			print max_ans
			return


def _inner_widespread_2(monsters, attemps, a, b):
	x = monsters-b*attemps
	dif = a-b
	re = 0
	for e in reversed(sorted(x)):
		if e<=0:
			break
		else:
			if e%dif==0:
				re = re+e/dif
			else:
				re = re + int(e/dif)+1
	return re


if __name__ == "__main__":
	widespread_2()

Submission status: Time Limit Exceeded

Solution code:
import sys
import numpy as np


if __name__ == "__main__":
    N, A, B = map(int, raw_input().split())
    health = [int(raw_input()) for i in range(N)]

    target = max(health)
    attack = 0
    while target > 0:
        target_index = health.index(target)

        health = [h - B for h in health]
        health[target_index] -= (A-B)
        attack += 1
        target = max(health)
        # print target
    print attack

Submission status: Time Limit Exceeded

Solution code:
def attack(h):
    m = h.index(max(h))
    h[m] -= A - B
    return list(map(lambda x:x-B, h))

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

result = 0

while True:
    check = len(list(filter(lambda x:x > 0, h)))
    if check:
        h = attack(h)
        result += 1
    else:
        break
print(result)

Submission status: Time Limit Exceeded

Solution code:
import math

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

m = sum(hs) // (a + (n-1)*b)-10
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Submission status: Time Limit Exceeded

Solution code:
import math

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

m = 0
M = sum(math.ceil(h/a) for h in hs)

def killable(p, hs, a, b):
    x = sum(max(0, math.ceil((h-p*b) / (a-b))) for h in hs)
    return x <= p

while(m+1 < M):
    c = (m+M) // 2
    if killable(c, hs, a, b):
        M = c
    else:
        m = c
print(M)

Submission status: Time Limit Exceeded

Solution code:
h=[]
N = input().split()
N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])
for i in range(N[0]):
    h.append(int(input()))
j=0
h.sort(reverse=True)
while True:
    j += 1
    h[0] -= N[1]
    for i in range(N[0] - 1):
        h[i+1] -= N[2]
    h.sort(reverse=True)
    if h[0] <= 0:
        break

print(j)

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import math
n, a, b = map(float, raw_input().split())
diff = a - b
h = []
n = int(n)
for _ in xrange(n):
    h.append(input())
h = sorted(h, reverse=True)

mi = math.ceil(h[-1] / a)
ma = math.ceil(h[0] / b)

while mi < ma:
    ce = math.ceil((ma + mi) / 2)
    bd = ce * b
    hh = map(lambda x: x-bd, h)
    c = 0
    for i in xrange(n):
        if hh[i] <= 0:
            break
        c += math.ceil(hh[i] / diff)

    if c > ce:
        mi = ce + 1
    else:
        ma = ce
print int(ma)

Submission status: Time Limit Exceeded

Solution code:
h=[]
N = input().split()
N[0] = int(N[0])
N[1] = int(N[1])
N[2] = int(N[2])
for i in range(N[0]):
    h.append(int(input()))
j=0
h.sort(reverse=True)
while True:
    j += 1
    h.sort(reverse=True)
    h[0] -= N[1]
    for i in range(N[0] - 1):
        h[i+1] -= N[2]
    h.sort(reverse=True)
    if h[0] <= 0:
        break

print(j)

Submission status: Accepted

Solution code:
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
ips = lambda:input().split()
import collections
import math
import itertools
import heapq as hq
import sys
ceil=math.ceil
n,a,b = ma()
H = []
for i in range(n):
    H.append(ni())
H.sort()
def isok(x):
    bs = b*x
    d=a-b
    cnt=0
    for h in H:
        if h>bs:
            cnt+=math.ceil((h-bs)/d)
    return cnt<=x

def bisect():
    ok = 10**9
    ng = 0
    x = (ok+ng)//2
    while ok-ng>1:
        if isok(x):
            ok=x
        else:
            ng=x
        x=(ok+ng)//2
    return ok
print(bisect())

Submission status: Accepted

Solution code:
def binary_search_int(ok, ng, test):
    """
    :param ok: solve(x) = True を必ず満たす点
    :param ng: solve(x) = False を必ず満たす点
    """
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if test(mid):
            ok = mid
        else:
            ng = mid
    return ok

##############################################################

import sys
input = sys.stdin.readline

def test(x):
    cnt = 0
    for h in H:
        if h-x*B>0:
            cnt += ceil((h-x*B)/(A-B))
    return cnt <= x

from math import ceil
N, A, B = map(int, input().split())
H = []
for _ in range(N):
    H.append(int(input()))

res = binary_search_int(10**9,-1,test)
print(res)