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:
N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]

ans = h
cnt = 0

while ans:
    max_ind = ans.index(max(ans))
    ans[max_ind] -= A
    
    for i in range(len(ans)):
        if i != max_ind:
            ans[i] -= B
    ans = [x for x in ans if x > 0]
    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

ans = h
cnt = 0

while ans:
    ans[0] -= A
    for i in range(1, len(ans)):
        ans[i] -= B
        
    ans = [x for x in ans if x > 0]
    ans.sort()
    ans.reverse()

    cnt += 1

print(cnt)

Submission status: Time Limit Exceeded

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

ans=0
while any(i>0 for i in h_n):
    h_n=[i-B for i in h_n]
    h_n[h_n.index(max(h_n))]+=B-A
    ans+=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 i in range(n)]

def enough(t):
    count = 0
    for hp in h:
        count += ceil(max(0, hp - b*t) / (a-b))
    if(count <= t):
        return True
    else:
        return False


high = ceil(max(h)/b)
low = 0
mid = ceil((high + low) / 2)
while(enough(mid)==enough(mid-1)):
    mid = (high + low) // 2
    if(enough(mid)):
        high = mid
    else:
        low = mid
print(mid)

Submission status: Time Limit Exceeded

Solution code:
from collections import Counter
N, A, B = map(int, input().split())
M = [int(input()) for i in range(N)]
d = A - B
ans = 0
while not all([True if m <= 0 else False  for m in M]):
    mx = max(M)
    CM = Counter(M)
    c = CM[mx]
    if c == N:
        j = A+(c - 1)*B
        if j > mx:
            break
        else:
            l = mx // j
            p = l * c
            ans += p
            M = [m - j*l for m in M]
    else:
        temp = list(set(M) - set([mx]))
        if d > (mx - max(temp)):
            break
        k = (mx - max(temp)) // d
        ans += c * k
        for i in range(N):
            if M[i] == mx:
                M[i] = M[i] - k * (A+(c-1)*B)
            else:
                M[i] = M[i] - k * c * B

while not all([True if m <= 0 else False for m in M]):
    mx = max(M)
    i = M.index(mx)
    for j in range(N):
        if j == i:
            M[j] = M[j] - A
        else:
            M[j] = M[j] - B
    ans += 1

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int, input().split())
nums = [0 for i in range(n)]
for i in range(n):
    nums[i] = int(input())
nums = sorted(nums, reverse = True)
count = 0
while nums[0]>0:
    nums[0] -= a
    for i in range(1,n):
        nums[i] -= b
    nums = sorted(nums, reverse = True)
    count += 1
print(count)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = list(map(int, input().split(" ")))
h = []
for _ in range(N):
    h.append(int(input()))
    
def argmax(l):
    return l.index(max(l))

ans = 0
while True:
    if max(h) <= 0:
        break
    max_idx = argmax(h)
    minus = [B for _ in range(N)]
    minus[max_idx] = A
    h = [x - y for x, y in zip(h, minus)]
    ans += 1

print (ans)

Submission status: Time Limit Exceeded

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

import numpy as np
import math as m

nh = np.array(h)

def testATK(ary, num, a, b):
    ary = np.array(ary)
    atk1 = b*num
    tmp = ary - atk1
    bommed = []
    for e in tmp:
        if(e>0):
            bommed.append(e)
    bommed = np.array(bommed)
    atk2 = a-b
    bomneed = list(map(m.ceil, (bommed/atk2)))
    acnt = np.sum(bomneed)
    if acnt > num:
        return "NO"
    else:
        return "YES"

imin = 1
imax = m.ceil(max(nh)/b)

def bs(ary, imin, imax):
    if (imax < imin):
        return imin
    else:
        imid = imin + (imax - imin)//2
        if (testATK(nh,imid,a,b)=="YES"):
            return bs(ary, imin, imid - 1)
        elif (testATK(nh,imid,a,b)=="NO"):
            return bs(ary, imid + 1, imax)
print(bs(nh, imin, imax))

Submission status: Time Limit Exceeded

Solution code:
import math

def calc(H, T, a, b):
    cnt = 0
    for h in H:
        cnt += math.ceil((h - b * T) / (a - b))
    if cnt <= T:
        return False
    else:
        return True

tmp = [int(n) for n in input().split()]
a = tmp[1]
b = tmp[2]
H = []

for i in range(tmp[0]):
    H.append(int(input()))
H = list(sorted(H))[::-1]
T = 1
while calc(H, T, a, b):
    T = T + 1

print(T)

Submission status: Time Limit Exceeded

Solution code:
tmp = [int(n) for n in input().split()]
a = tmp[1]
b = tmp[2]
H = []
for i in range(tmp[0]):
    H.append(int(input()))

cnt = 0
while True:
    H = list(sorted(H))[::-1]
    flg = 0
    cnt += 1
    H[0] = H[0] - a
    for i in range(len(H)):
        if i == 0:
            if H[0] > 0:
                flg = 1
            continue
        H[i] = H[i] - b
        if H[i] > 0:
            flg = 1
    if flg == 0:
        break

print(cnt)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, A, B = [int(i) for i in input().split()]
if 1 > N or N > 10**5 or A <= B or 1 > A or A > 10**9 or 1 > B or B > 10**9:
    print("error.")
    sys.exit()

h = []

for i in range(N):
    h.append(int(input()))
    if 1 > h[i] or h[i] > 10**9:
        print("error.")
        sys.exit()

count = 0
while len(h) != 0:
    h.sort()
    h[-1] -= A

    for i in range(len(h[:-1])):
        h[i] -= B

    for i in h[:]:
        if i <= 0:
            del h[h.index(i)]

    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import sys

N, A, B = [int(i) for i in input().split()]
if 1 > N or N > 10**5 or A <= B or 1 > A or A > 10**9 or 1 > B or B > 10**9:
    print("error.")
    sys.exit()

h = []

for i in range(N):
    h.append(int(input()))
    if 1 > h[i] or h[i] > 10**9:
        print("error.")
        sys.exit()

count = 0
while len(h) != 0:
    max_i = h.index(max(h))
    h[max_i] -= A

    for i in range(len(h)):
        if i != max_i:
            h[i] -= B

    for i in h[:]:
        if i <= 0:
            del h[h.index(i)]

    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:

import numpy as np

N, A, B = (int(e) for e in input().split())

ary = np.zeros(N)
for i in range(N):
    ary[i] = int(input())


d = A - B

def attack(c, a):
    tmpary = np.copy(a)
    idx = np.argmax(tmpary)
    tmpary -= c * B

    cnt = 0
    for i in range(N):
        if tmpary[i] <= 0:
            continue
        cnt += np.ceil(tmpary[i] / d)

    return cnt <= c

###

maxval = np.max(ary)
cnt = int(np.ceil(maxval / B))
upper = cnt
lower = 0
cnt_p = 0

while cnt_p != cnt:
    cnt_p = cnt
    cnt = np.ceil((upper + lower) / 2)
    if attack(cnt, ary):
        upper = cnt
    else:
        lower = cnt

print(int(cnt))

Submission status: Time Limit Exceeded

Solution code:

import numpy as np

N, A, B = (int(e) for e in input().split())

ary = np.zeros(N)
for i in range(N):
    ary[i] = int(input())


###

d = A - B
cnt = 0
while np.any(ary > 0):
    idx = np.argmax(ary)
    ary -= B
    ary[idx] -= d
    cnt += 1

print(cnt)

### TLE

Submission status: Time Limit Exceeded

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

while max(h)>0:
    h=sorted(h,reverse=True)
    h[0]-=A
    for j in range(len(h)-1):
        h[j+1]-=B
    count+=1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int, input().split())
nums = [0 for i in range(n)]
for i in range(n):
    nums[i] = int(input())
nums = sorted(nums, reverse = True)
count = 0
while nums[0]>0:
    nums[0]=nums[0]-a
    for i in range(1,n):
        nums[i]=nums[i]-b
    nums = sorted(nums, reverse = True)
    count += 1
print(str(count))

Submission status: Time Limit Exceeded

Solution code:
import heapq
 
def f(A, B, hs):
    hs = [-h for h in hs]
    heapq.heapify(hs)
    iterations = 0
    while hs[0] < 0:
        hi = heapq.heappop(hs)
        hs = [h + B for h in hs]
        heapq.heappush(hs, hi + A)
        iterations += 1
    return iterations
 
N, A, B = map(int, input().split())
hs = []
for _ in range(N):
    hs.append(int(input()))
print(f(A, B, hs))

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

h.sort(reverse=True)


def check(count_target, h, a, b):
    count = 0

    for i in h:
        if i >= count_target * b:
            count += math.ceil((i - count_target * b) / (a-b))
    return count_target - count


count = 1
while check(count, h, a, b) < 0:
    count *= 2

count /= 2
basis_count = count

while basis_count >= 1:

    if check(count + basis_count - 1, h, a, b) < 0:
        count += basis_count
    basis_count /= 2


while check(count,h,a,b) < 0:

    count += 1

print(int(count))

Submission status: Time Limit Exceeded

Solution code:
n,a,b = [int(x) for x in input().split()]

monsters_hp = sorted([int(input()) for _ in range(n)])

use_magic_times = 0
any_monster_alive = True

while any_monster_alive:
	for i in range(n-1):
		monsters_hp[i] -= b
	monsters_hp[n-1] -= a
	monsters_hp.sort()
	use_magic_times += 1
	if monsters_hp[n-1] <= 0:
		any_monster_alive = False

print(use_magic_times)

Submission status: Time Limit Exceeded

Solution code:
class Monster():
	def __init__(self, hp, A, B):
		self.hp = hp
		self.live = 1
		self.center = A
		self.side = B
	
	def is_die(self):
		if self.hp <= 0:
			self.live = 0
	
	def center_bombed(self):
		self.hp -= self.center
		self.is_die()
	
	def side_bombed(self):
		self.hp -= self.side
		self.is_die()
	
N, A, B =[int(i) for i in input().split()]
monsters = []
counter = 0
for i in range(N):
	h = int(input())
	monsters.append(Monster(h, A, B))

while True:
	NN = len(monsters)
	hp_of_monsters = [m.hp for m in monsters]
	MAX = max(hp_of_monsters)
	number = hp_of_monsters.index(MAX)
	for i in range(NN):
		if i == number:
			monsters[i].center_bombed()
		else:
			monsters[i].side_bombed()
	counter += 1
	monsters = [m for m in monsters if m.live == 1]
	if len(monsters) == 0:
		print(counter)
		break

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n,a,b = map(int,input().split())
h = [int(input()) for i in range(n)]
k = sorted(h,reverse = True)
cnt = 0
while k[0]>0:
    h[h.index(k[0])] -= a-b
    h = list(np.array(h)-b)
    
    k = sorted(h, reverse =True)
    cnt +=1
    
print(cnt)

Submission status: Time Limit Exceeded

Solution code:
lines, damage_A, damage_B = map(int, input().split(" "))
monsters_hp = []
for line in range(lines):
    monsters_hp.append(int(input()))
cnt = 0
while max(monsters_hp) > 0:
    monsters_hp_tmp = [i - damage_B for i in monsters_hp]
    monsters_hp_tmp[monsters_hp_tmp.index(max(monsters_hp_tmp))] -= (damage_A - damage_B)
    monsters_hp = monsters_hp_tmp
    cnt += 1
print(cnt)

Submission status: Time Limit Exceeded

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

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

h.sort()
h.reverse()

count = 0

while h[0] > 0:
    h = list(map(lambda x: x - B, h))
    h[0] -= A - B

    h.sort()
    h.reverse()
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int,input().split())
dif = a-b
ene = []
count = 0
for i in range(n):
    ene.append(int(input()))

def live(hp):
    for x in hp:
        if x > 0:
            return True
    else:
        return False

while(live(ene)):
    for i in range(n):
        ene[i] = ene[i] - b
    ene[ene.index(max(ene))] = ene[ene.index(max(ene))] - dif
    count += 1

print(count)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
 
n, a, b = map(int, input().split())
 
monster = list(int(input()) for i in range(n))
monster.sort()
 
c = b * np.ones(n)
c[n - 1] = a
 
count = 0
 
for i in range(1000000) :
  monster = monster - c
  if monster[n - 1] < monster[n - 2] :
    monster.sort()
  count = count + 1
  if monster[n - 1] <= 0 :
    break
 
print (count)

Submission status: Time Limit Exceeded

Solution code:
All=(input(""))
All=All.split(" ")
N=int(All[0])
A=int(All[1])
B=int(All[2])
h=[]
while N:
    h.append(int(input("")))
    N-=1
h.sort(reverse=True)
lenh=len(h)
sun=0
while h[0]>0:
    sun+=1
    h[0]-=A
    for i in range(1,lenh):
        h[i]-=B
    h.sort(reverse=True)
print(str(sun))

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3

s = input()
N = int(s.split()[0])
A = int(s.split()[1])
B = int(s.split()[2])

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

i = 0
while True:
    h.sort()
    if h[-1] <= 0:
        print(i)
        break
    else:
        i += 1
        h[-1] -= (A-B)
        for j in range(len(h)):
            h[j] -= B

Submission status: Time Limit Exceeded

Solution code:
import math
N,A,B=map(int,input().split())
S=[]
for i in range(N):
  S+=[int(input())] 
S.sort(reverse=1)
count=0

def Check(T):
  count=0
  for i in range(N):
    count+=max(0,math.ceil((S[i]-B*T)/(A-B)))
  if count<=T:
    return 1
  else:
    return 0

L=1
while True:
  if S[0]/B >=2**L:
    L+=1
  else:
    break

T=2**L#checkしたいナンバー。
for l in range(L,0,-1):
  if Check(T)==1:
    T-=2**(l-1)
  elif Check(T)==0:
    T+=2**(l-1)
if Check(T)==0:
  print(T+1)
else:
  print(T)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,A,B=map(int,input().split())
S=[]
for i in range(N):
  S+=[int(input())] 
S.sort(reverse=1)
count=0

def Check(T):
  count=0
  for i in range(N):
    if (S[i]-B*T)/(A-B)%1==0:
      count+=max(0,int((S[i]-B*T)/(A-B)))
    else:
      count+=max(0,int((S[i]-B*T)/(A-B))+1)
  if count<=T:
    return 1
  else:
    return 0

L=1
while True:
  if S[0]/B >=2**L:
    L+=1
  else:
    break

T=2**L#checkしたいナンバー。
for l in range(L,0,-1):
  if Check(T)==1:
    T-=2**(l-1)
  elif Check(T)==0:
    T+=2**(l-1)
if Check(T)==0:
  print(T+1)
else:
  print(T)

Submission status: Time Limit Exceeded

Solution code:
#coding=UTF-8

def turn_check(zikan,direct,around):
    nokori_naka=zikan
    for idx in range(0,N,1):
        rem_hp=kirei_HP[idx]-around*zikan
        if rem_hp > 0:
            myon= rem_hp//(direct-around) + (0 if rem_hp%(direct-around)==0 else 1)
        
            nokori_naka=nokori_naka-myon
            if nokori_naka < 0:
                return False
        else: #以降も周辺攻撃のみで倒せる
            return True

    return True


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
A=int(hyo[1])
B=int(hyo[2])

HP=[]
for idx in range(0,N,1):
    HP.append(int(input()))

kirei_HP=sorted(HP,reverse=True)
kagen=kirei_HP[0]// B + 1
tansaku=kagen//2
while True:
    if turn_check(tansaku,A,B):
        kagen=tansaku
        tansaku=kagen//2
    else:
        if tansaku + 1 == kagen: #丁度境目を見付けたら
            break
        else:
            tansaku=(tansaku+kagen)//2

print(kagen)

Submission status: Time Limit Exceeded

Solution code:
#coding=UTF-8

def turn_check(zikan,direct,around):
    nokori_naka=zikan
    for idx in range(0,N,1):
        rem_hp=max(HP[idx]-around*zikan,0)
        myon= rem_hp//(direct-around) + (0 if rem_hp%(direct-around)==0 else 1)
        
        nokori_naka=nokori_naka-myon
        if nokori_naka < 0:
            return False

    return True


mozir=input()
hyo=mozir.split(' ')
N=int(hyo[0])
A=int(hyo[1])
B=int(hyo[2])

HP=[]
for idx in range(0,N,1):
    HP.append(int(input()))

kagen=max(HP)// B + 1
tansaku=kagen//2
while True:
    if turn_check(tansaku,A,B):
        kagen=tansaku
        tansaku=kagen//2
    else:
        if tansaku + 1 == kagen: #丁度境目を見付けたら
            break
        else:
            tansaku=(tansaku+kagen)//2

print(kagen)

Submission status: Time Limit Exceeded

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

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

while max(H) > 0:
    index = max(enumerate(H), key=lambda x: x[1])[0]
    H[index] -= A
    for i in range(len(H)):
        if i != index:
            H[i] -= B
    c += 1

print(c)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, A, B = map(int, raw_input().split())
hppp = [int(raw_input()) for i in range(N)]
hps = np.array(hppp)


def enough(T, hp0):
    hp = hp0 - B * T
    for h in hp:
        T -= h / (A - B)
        if h != (h / (A - B)) * (A - B):
            T -= 1
    return True if T >= 0 else False


def binarySearch(hp, low, high):
    while (low != high):
        center = (low + high) / 2
        if enough(center, hp):
            high = center
        else:
            low = center + 1
    return low


def calc_max(hp):
    c = 0L
    for h in hp:
        c += h / B + 1
    return c


print binarySearch(hps, 0, calc_max(hps))

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n, a, b = map(int, raw_input().split())
h = []
for i in xrange(n):
    h.append(int(raw_input()))
h = np.array(h)
count = 0
adiff = a - b
while(1):
    h = h - b
    h[np.argmax(h)] -= adiff
    count += 1
    if all(h <= 0):
        break
print count

Submission status: Time Limit Exceeded

Solution code:
import sys
N,A,B=map(int,input().split())
S=[]
for i in range(N):
  S+=[int(input())] 
count=0

def Check(T):
  count=0
  for i in range(N):
    count+=int((S[i]-B*T)/(A-B))
  if count<=T:
    return 1
  else:
    return 0

L=-1#二分探索の指数
T=1#checkしたいナンバー。
while True:
  if Check(T)==0:
    L+=1
    T+=2**L
  if Check(T)==1:
    L-=1
    if L==0:
      print(T)
      sys.exit() 
    T-=2**L

Submission status: Time Limit Exceeded

Solution code:
N,A,B=(int (i) for i in input(). split ())
h=[int (i) for i in range (N)]
h.sort()
nd=1
while nd==1:
    h[0]-=A
    i=0
    while i<N-1:
        h[i]-=B
        i+=1

Submission status: Time Limit Exceeded

Solution code:
from bisect import *
from math import *
N,A,B = map(int,input().split())
H = []
for _ in range(N):
  H.append(int(input()))
H.sort()
ans = 0
while(H):
  i = H.index(H[-1])
  l = len(H)-i
  v = H.pop()
  if H:
    t = max(1,v//((l+len(H))*A))
    ans += t
    H = [h-t*B for h in H if h>t*B]
    if v > t*A:
      insort(H,v-t*A)
  else:
    ans += (v+A-1)//A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, A, B = [int(x) for x in input().split()]
h = np.zeros(N)
for i in range(N):
	h[i] = int(input())	
	
count = 0
while len(h) > 0:
	b = [B] * len(h)
	h -= b
	h[h.argmax()] -= A - B
	h = h[h > 0]
	count += 1
	
print(count)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

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

monster = list(int(input()) for i in range(n))
monster.sort()

c = b * np.ones(n)
c[n - 1] = a

count = 0

for i in range(1000000) :
  monster = monster - c
  if monster[n - 1] < monster[n - 2] :
    monster.sort()
  count = count + 1
  if monster[n - 1] <= 0 :
    break;

print (count)

Submission status: Time Limit Exceeded

Solution code:
from bisect import *
from math import *
N,A,B = map(int,input().split())
H = []
for _ in range(N):
  H.append(int(input()))
H.sort()
ans = 0
while(H):
  l = len(H)
  v = H.pop()
  if H:
    t = max(1,v//(l*A))
    ans += t
    H = [h-t*B for h in H if h>t*B]
    if v > t*A:
      insort(H,v-t*A)
  else:
    ans += (v+A-1)//A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,A,B=map(int,input().split())
S=[]
for i in range(N):
  S+=[int(input())] 
count=0
S.sort()
C=A-B
h=[S[0]]
for i in range(N-1):
  if S[i+1]>=S[0]*(B/A):
    h+=[S[i+1]]
  else:
    break

N=len(h)

while True:
  h.sort(reverse=1)
  if h[0]<=0:
    print(count)
    sys.exit()
  if (h[0]/A)%1==0:
    t=int(h[0]/A)
  else:
    t=int(h[0]/A)+1
  for i in range(N):
    h[i]-=B*t
  for j in range(t):
    h.sort(reverse=1)
    h[0]-=C
  count+=t

Submission status: Time Limit Exceeded

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

time = []
for i in range(N):
    time.append(int(h[i] / B))
    if h[i] % B != 0:
        time[-1] += 1
result = max(time)

for i in range(N):
    h[i] -= (B * result)

while True:
    time = []
    for i in range(N):
        h[i] += B
        if 0 < h[i]:
            time.append(h[i] / (A - B))
            if h[i] % (A - B) != 0:
                time[-1] += 1
        else:
            time.append(0)
    if sum(time) <= result - 1:
        result -= 1
    else:
        break

print(result)

Submission status: Time Limit Exceeded

Solution code:
from bisect import *
from math import *
N,A,B = map(int,input().split())
H = []
for _ in range(N):
  H.append(int(input()))
H.sort()
ans = 0
while(H):
  l = len(H)
  v = H.pop()
  if H:
    t = max(1,H[0]//(l*B),v//(l*A))
    ans += t
    H = [h-t*B for h in H if h>t*B]
    if v > t*A:
      insort(H,v-t*A)
  else:
    ans += (v+A-1)//A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
from bisect import *
from math import *
N,A,B = map(int,input().split())
H = []
for _ in range(N):
  H.append(int(input()))
H.sort()
ans = 0
while(H):
  l = len(H)
  v = H.pop()
  if H:
    t = max(1,H[0]//(l*A))
    ans += t
    H = [h-t*B for h in H if h>t*B]
    if v > t*A:
      insort(H,v-t*A)
  else:
    ans += (v+A-1)//A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n,a,b = map(int, input().split())
h=[]
for i in range(n):
    h.append(int(input()))
cnt=0
while sum(h)!=0:
    h.sort()
    h.reverse()
#    print("")
#    print(h)
    k1 = int((h[0])/(a))
    if h[n-1]==0:
        k2=k1
    else:
        k2 = int((h[n-1])/(b))
    k = int(max(1,k1/10, k2/10))
    h[0]-=a*k
    if h[0]<0:
        h[0]=0
    for i in range(1,n):
        h[i]-=b*k
        if h[i]<0:
            h[i]=0
    cnt+=k
#    print(k1,k2,k)
#    print(h)
print(cnt)

Submission status: Time Limit Exceeded

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

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

enemy=N
counter=0

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

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

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

 #   print(h)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
from bisect import *
from math import *
N,A,B = map(int,input().split())
H = []
for _ in range(N):
  H.append(int(input()))
H.sort()
ans = 0
while(H):
  l = len(H)
  v = H.pop()
  if H:
    t = max(1,H[0]//(l*A),(v-H[0])//(l*(A-B)))
    ans += t
    H = [h-t*B for h in H if h>t*B]
    if v > t*A:
      insort(H,v-t*A)
  else:
    ans += (v+A-1)//A
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
N,A,B=map(int,input().split())
S=[]
for i in range(N):
  S+=[int(input())] 
count=0
S.sort()
h=[S[0]]
for i in range(N-1):
  if S[i+1]>=S[0]*(B/A):
    h+=[S[i+1]]
  else:
    break

N=len(h)

while True:
  h.sort(reverse=1)
  if h[0]<=0:
    print(count)
    sys.exit()
  if (h[0]/A)%1==0:
    t=int(h[0]/A)
  else:
    t=int(h[0]/A)+1
  h[0]-=A*t
  for i in range(N-1):
    h[i+1]-=B*t
  count+=t
  if h[N-1]<=-A:
    if (h[N-1]/A)%1==0:
      t=-int(h[N-1]/A)
    else:
      t=-int(h[N-1]/A)
    h[N-1]+=t*(A-B)
    for i in range(N):
      h[i]+=t*B
    count-=t

Submission status: Time Limit Exceeded

Solution code:
#coding:utf-8



if __name__ == '__main__':

	count = 0

	l = map(int, raw_input().split())
	N = l[0]
	A = l[1]
	B = l[2]
	monster = [input() for i in range(N)]

	while True:

		if max(monster) <= 0:
			print count
			break

		target = monster.index(max(monster))
		
		count += 1 
		for i in range(0,N):
			if i == target:
				monster[i] -= A
			else:
				monster[i] -= B

Submission status: Time Limit Exceeded

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

while True:
  h.sort(reverse=1)
  if h[0]<=0:
    print(count)
    sys.exit()
  if (h[0]/A)%1==0:
    t=int(h[0]/A)
  else:
    t=int(h[0]/A)+1
  h[0]-=A*t
  for i in range(N-1):
    h[i+1]-=B*t
  count+=t
  if h[N-1]<=-A:
    if (h[N-1]/A)%1==0:
      t=-int(h[N-1]/A)
    else:
      t=-int(h[N-1]/A)
    h[N-1]+=t*(A-B)
    for i in range(N):
      h[i]+=t*B
    count-=t

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-
import numpy as np

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

list=[]
for x in range(N):
    xx = int(raw_input())
    list.append(xx)

list2 = np.array(list)

kaisu = 0


while list2.max()>0:    
    index = list2.argmax()
    minus = np.zeros(N)
    minus[:] = B
    minus[index] = A
    list2 =list2- minus
    kaisu = kaisu+1

print kaisu

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, raw_input().split())
monsters = []
for i in range(N):
    monsters.append(input())
monsters.sort(reverse=True)
count = 0
while monsters:
    n = 1
    if len(monsters) == 1:
        if monsters[0]%A == 0:
            count += monsters[0]/A
        else:
            count += monsters[0]/A+1
        break
    while monsters[0]-A*n >= monsters[1]-B*n:
        n += 1
    count += n
    monsters = [monsters[0]-A*n] + map(lambda monster:monster-B*n, monsters[1:])
    monsters = filter(lambda monster:monster>0, monsters)
    monsters.sort(reverse=True)
print count

Submission status: Time Limit Exceeded

Solution code:
N , A , B = map(int, input().split())
monsters = []
cnt = 0

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

while True:
    monsters.sort(reverse=True)
    if monsters[0] <= 0:
        print(cnt)
        break
    
    monsters[0] -= A
    cnt += 1
    
    for j in range(1,N):
        monsters[j] -= B

Submission status: Time Limit Exceeded

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

result = 0

while True:
    flag = True
    for i in range(N):
        if 0 < h[i]:
            flag = False
            break
    if flag:
        break

    index_max = h.index(max(h))
    for i in range(N):
        if i == index_max:
            h[i] -= A
        else:
            h[i] -= B
    result += 1

print(result)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, A, B = map(int, input().split())
h = np.array([int(input()) for i in range(N)])
x = np.array([B] * (N - 1))
x = np.append(x, np.array([A]))
c = 0
m = max(h)

while m > 0:
	h = np.sort(h)
	h = h - x
	c += 1
	m = max(h)

print(c)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

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

enemy=N
counter=0

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

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

 #   print(h)
print(counter)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np

N, A, B = map(int, input().split())
h = np.array([int(input()) for i in range(N)])
x = np.array([B] * (N - 1))
x = np.append(x, np.array([A]))
c = int(0)
m = int(max(h))

while m > 0:
	h = np.sort(h)
	h = h - x
	c += 1
	m = int(max(h))

print(c)

Submission status: Time Limit Exceeded

Solution code:
N, A, B = map(int, raw_input().split())
monsters = []
for i in range(N):
    monsters.append(input())
monsters.sort(reverse=True)
count = 0
while monsters:
    count += 1
    monsters = [monsters[0]-A] + map(lambda monster:monster-B, monsters[1:])
    monsters = filter(lambda monster:monster>0, monsters)
    monsters.sort(reverse=True)
print count

Submission status: Time Limit Exceeded

Solution code:
def allzero(lst):
	for i in range(0, len(lst)):
		if lst[i] > 0:
			return False
	return True

inpt = map(int, raw_input().split())
n = inpt[0]
a = inpt[1]
b = inpt[2]
monster = []
for i in range(0, n):
	monster.append(int(raw_input()))
monster.sort()
cnt = 0
while not(allzero(monster)):
	monster = map(lambda x:x-b, monster)
	monster[-1] -= a - b
	monster.sort()
	cnt += 1

print cnt

Submission status: Time Limit Exceeded

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

    if max(H) // A > 100000:
        k = 10000
    else:
        k = 1

    h = H[:]
    ans = 0
    while True:
        max_ = max(h)
        if max_ <= 0:
            break
        i = 0
        while i < N:
            if h[i] == max_:
                h[i] -= A * k
                max_ = None
            else:
                h[i] -= B * k
            i += 1
        ans += 1

    print(ans * k)

main()

Submission status: Time Limit Exceeded

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

while(True):
 h.sort()
 if h[-1] <= 0:
  break
 else:
   for x in range(n-1):
       h[x] -= b
   h[-1] -= a
   count += 1

print(count)