Problem:
 Score : 400 points    Problem Statement You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1 , Katana 2 , … , Katana N , and can perform the following two kinds of attacks in any order:   Wield one of the katana you have. When you wield Katana i  (1 ≤ i ≤ N) , the monster receives a_i points of damage. The same katana can be wielded any number of times.  Throw one of the katana you have. When you throw Katana i  (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.   The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?      Constraints  1 ≤ N ≤ 10^5  1 ≤ H ≤ 10^9  1 ≤ a_i ≤ b_i ≤ 10^9  All input values are integers.         Input Input is given from Standard Input in the following format:  N  H  a_1  b_1  :  a_N  b_N       Output Print the minimum total number of attacks required to vanish the monster.        Sample Input 1 1 10
3 5      Sample Output 1 3  You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.       Sample Input 2 2 10
3 5
2 6      Sample Output 2 2  In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.       Sample Input 3 4 1000000000
1 1
1 10000000
1 30000000
1 99999999      Sample Output 3 860000004       Sample Input 4 5 500
35 44
28 83
46 62
31 79
40 43      Sample Output 4 9

Solution (Python):
def main():
    N, H = map(int, input().split())
    AB = (tuple(map(int, input().split())) for _ in [0] * N)
    a, b = [], []
    appenda, appendb = a.append, b.append
    for i, j in AB:
        appenda(i)
        appendb(j)

    amax = max(a)
    b = [i for i in b if i > amax]
    b.sort(reverse=1)
    energy = H
    if energy <= sum(b):
        attack = 0
        i = 0
        while energy > 0:
            energy -= b[i]
            attack += 1
            i += 1
    else:
        energy -= sum(b)
        attack = (energy + amax - 1) // amax + len(b)

    print(attack)

main()

Solution (Python):
def main():
    N, H = map(int, input().split())
    AB = (tuple(map(int, input().split())) for _ in [0] * N)
    a, b = [], []
    appenda, appendb = a.append, b.append
    for i, j in AB:
        appenda(i)
        appendb(j)

    amax = max(a)
    b = [i for i in b if i > amax]
    b.sort(reverse=1)
    energy = H
    if energy <= sum(b):
        attack = 0
        i = 0
        while energy > 0:
            energy -= b[i]
            attack += 1
            i += 1
    else:
        energy -= sum(b)
        attack = (energy + amax - 1) // amax + len(b)

    print(attack)

main()

Solution (Python):
import math

N,H=map(int, input().split())

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

ans=0

B.sort(reverse=True)
Am=max(A)
for i in range(N):
    if B[i]>=Am:
        H-=B[i]
        ans+=1
    if H<=0:
        break

if H>0:
    ans+=math.ceil(H/Am)

print(ans)

Solution (Python):
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0],reverse=True)
mainweapon = ab[0]
del ab[0]
new_ab =[]
for i in range(N-1):
    if ab[i][1] > mainweapon[0]:
        new_ab.append(ab[i])
new_ab.sort(key=lambda x:x[1],reverse=True)

attack = 0

for i in range(len(new_ab)):
    H -= new_ab[i][1]
    attack += 1
    if H <= 0:
        break

if H > 0:
    attack += math.ceil((H - mainweapon[1])/mainweapon[0])
    attack += 1

print(attack)

Solution (Python):
N, H = tuple(map(int, input().split(' ')))
katanas = [list(map(int, input().split(' '))) for _ in range(0, N)]

normaldmbs = list(map(lambda x: x[0], katanas))
max_normal_dmg = max(normaldmbs)

throwables = list(map(lambda x: x[1], filter(lambda x: x[1] > max_normal_dmg, katanas)))
throwables.sort(reverse=True)

cnt = 0

for v in throwables:
    H -= v
    cnt += 1
    if H <= 0:
        break

if H > 0:
    if H % max_normal_dmg == 0:
        cnt += int(H / max_normal_dmg)
    else:
        cnt += int(H / max_normal_dmg) + 1


print(cnt)

Solution (Python):
def main():
    N, H = map(int, input().split())
    ab = [
        [i] + list(map(int, input().split()))
        for i in range(N)
    ]

    
    editorial(H, ab)


def editorial(H, ab):
    """
    max_a より大きいbを使う方針はOK
    max_a を持ち max_aより大きいbを持つ刀をどうするか？

    基本は合っていた
    投げた後のことを考えていたが
    投げるのは倒すときでよいので、それまでは切り続ける
    というのが解説の投げた後も使って良いということ
        b ... b + (a_max ... a_max + b_last)
        b ... b + (b_last + a_max ... a_max)
    """
    sorted_a = sorted(ab, key=lambda x: x[1], reverse=True)
    sorted_b = sorted(ab, key=lambda x: x[2], reverse=True)
    max_a = sorted_a[0][1]

    ans = 0
    for _, _, b in sorted_b:
        if max_a > b:
            break

        H -= b
        ans += 1
        if H <= 0:
            print(ans)
            return

    ans += (H + max_a - 1) // max_a
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
N, H = (int(i) for i in input().split())
A = []
B = []
for index in range(N):
	a, b = (int(i) for i in input().split())
	A.append(a)
	B.append(b)

arg_sorted = sorted(range(N), key=lambda k: B[k], reverse=True)

B_sorted = []
for i in arg_sorted:
	B_sorted.append(B[i])

A_max = max(A)
hits = 0

for b in B_sorted:
	if H <= 0:
		break
	if b > A_max:
		hits += 1
		H -= b
	else:
		break

if H > 0:
	hits += (H-1) // A_max + 1

print(hits)

Solution (Python):
import math
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + math.ceil(hp / max_slash))

n, hp = map(int, input().split())
takanas = [list(map(int, input().split())) for _ in range(n)]
katana(hp, takanas)

Solution (Python):
def answer():
    import sys
    input = sys.stdin.readline
    wield = 0
    l = []
    N, H = map(int, input().split())
    for i in range(N):
        a, b = map(int, input().split())
        l.append(b)
        wield = max(a, wield)
    l.sort(reverse=True)
    ret = 0
    for a in l:
        if H <= 0:
            break
        if a > wield:
            ret += 1
            H -= a
        else:
            break
    if H > 0:
        ret += (H + wield - 1) // wield
    print(ret)
  
answer()

Solution (Python):



import sys
from math import ceil

def main():
    n, h = map(int, sys.stdin.readline().split())
    k = tuple(tuple(map(int, line.split())) for line in sys.stdin.readlines())

    max_a = max(x[0] for x in k)
    b = tuple(sorted((x[1] for x in k if x[1] > max_a), reverse=True))

    cnt = 0
    for bi in b:
        h -= bi
        cnt += 1
        if h <= 0:
            break
    else:
        cnt += ceil(h / max_a)

    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
n,h = map(int,input().split())
b = []
sum_b = 0
max_a = 0
for _ in range(n):
    ta,tb = map(int,input().split())
    b.append(tb)
    sum_b += tb
    if ta > max_a:
        max_a = ta

b.sort()
sum_b2 = 0
count = 0
bbb = 0

while True:
    if (len(b) > 0):
        bbb=b.pop()
    if bbb > max_a:
        sum_b2 += bbb
        bbb = 0
        count += 1
    else:
        if (h-sum_b2)%max_a == 0:
            print (count + (h-sum_b2)//max_a)
        else:
            print (count + (h-sum_b2)//max_a + 1)
        break
    if sum_b2 >= h:
        print (count)
        break

Solution (Python):
n,h = map(int,input().split())
a = []
b = []
for i in range(n):
	atemp,btemp = map(int,input().split())
	a.append(atemp)
	b.append(btemp)
amax = max(a)
b.sort()
total = 0
counter = 0
i = n-1
while i >= 0 and b[i] >= amax and total < h:
	total += b[i]
	counter += 1
	i += -1
if total < h:
	if (h-total)%amax == 0:
		counter = counter + (h-total)//amax
	else:
		counter = counter + (h-total)//amax + 1
print(counter)

Solution (Python):
import math

s=input()
s=s.split(' ')
honsu = int(s[0])
HP  = int(s[1])

kill=[]
throw=[]
tmp_throw=[]
for i in range(honsu):
	a,b = input().split(' ')
	kill.append(int(a))
	throw.append(int(b))
	tmp_throw.append(int(b))




count=0
a_max=max(kill)
b_sum=0


tmp_throw.sort()
tmp_throw.reverse()
suma=0
for i,data in enumerate(tmp_throw):
	if data >=a_max :
		suma+=int(data)
		if suma >= HP:
			print(i+1)
			exit()

for i in tmp_throw:
	if i >=a_max :
		count+=1
		b_sum += i
	else:
		break

HP = HP - b_sum
temp=0
count=count+ math.ceil(HP/a_max)

print(count)

Solution (Python):
import sys
import math
N, H = map(int, input().split())

a = []
b = []
num_attack = 0

for _ in range(N):
	a_i, b_i = map(int, input().split())
	a.append(a_i)
	b.append(b_i)
max_a = max(a)
Strong_b = [b_i for b_i in b if b_i > max_a]

if sum(Strong_b) >= H:
	Strong_b = sorted(Strong_b, reverse = True)
	for i in range(N):
		H -= Strong_b[i]
		if H <= 0:
			print(i+1)
			sys.exit()

H -= sum(Strong_b)
num_attack = len(Strong_b) + math.ceil(H/max_a)
print(num_attack)

Solution (Python):


import sys

n, h = [int(e) for e in raw_input().split()]

kl = []
for i in range(0, n):
    a, b = [int(e) for e in raw_input().split()]
    kl.append((b, 0))
    kl.append((a, 1))

kl.sort(reverse=True)


n = 0
i = 0
while h > 0:
    k = kl[i]
    if k[1] == 0:
        h -= k[0]
        i += 1
        n += 1
    else:
        n = n + ((h + k[0] - 1) / k[0])
        break

sys.stdout.write('%d\n' % (n))
sys.stdout.flush()

Solution (Python):
N, H = map(int, input().split())
a = [0 for i in range(N)]
b = [0 for i in range(N)]
s = []
for i in range(N):
    a[i], b[i] = map(int, input().split())
    s.append(a[i])
    s.append(b[i])

a.sort(reverse=True)
b.sort(reverse=True)
s.sort(reverse=True)
low=0
high=2*N
t=(low+high) // 2
while(low<=high):
    if s[t] == a[0]:
        break
    elif s[t] < a[0]:
        high=t
    else:
        low=t+1
    t=(low+high) // 2

m = 0
P = 0
flag = False
for i in range(t+1):
    m+=1
    P+=s[i]
    if P >= H:
        flag = True
        break

if flag == False:
    k = (H-P)//a[0]
    m += k
    P += k * a[0]
    if H > P:
        m+=1

print(m)

Solution (Python):
import numpy as np
import sys

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








arr_a = np.array(a)
a_max = max(a)
idx_tmp = np.where(arr_a == a_max)[0]
b_min = b[idx_tmp[0]]
idx_b_min = idx_tmp[0]
for i in range(1, np.shape(idx_tmp)[0]):
    if b_min > b[idx_tmp[i]]:
        b_min = b[idx_tmp[i]]
        idx_b_min = idx_tmp[i]
b[idx_b_min] = 0
b.sort()

sum_b = 0
ans = 0

for i in range(n - 1):
    if b[-1 - i] < a_max:
        break
    sum_b += b[-1 - i]
    ans += 1
    if sum_b >= h:
        print(ans)
        sys.exit()

h_tmp = h - sum_b - b_min
ans += 1
if h_tmp > 0:
    ans += (h_tmp + a_max - 1) // a_max

print(ans)

Solution (Python):

"""
https://beta.atcoder.jp/contests/abc085/tasks/abc085_d

"""
import sys
from sys import stdin
from math import ceil
input = stdin.readline


def solve(slashes, throws, H):
    max_slash = max(slashes)
    v_throws = [x for x in throws if x > max_slash]
    v_throws.sort(reverse=True)
    total_throws = sum(v_throws)
    if total_throws > H:
        ans = len(v_throws)
        while total_throws >= H:
            p = v_throws.pop()
            total_throws -= p
            ans -= 1
        return ans + 1

    return ceil((H-total_throws) / max_slash) + len(v_throws)


def main(args):
    slashes = []
    throws = []

    N, H = map(int, input().split())
    for _ in range(N):
        a, b = map(int, input().split())
        slashes.append(a)
        throws.append(b)
    ans = solve(slashes, throws, H)
    print(ans)


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

Solution (Python):
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
	a[i], b[i] = map(int, input().split())
a_max = max(a)
ans = dmg = 0
for dmg_i in sorted([bi for bi in b if bi > a_max], reverse=True):
	dmg += dmg_i
	ans += 1
	if dmg >= H:
		print(ans)
		break
else:
	print(ans + (H - dmg + a_max - 1) // a_max)

Solution (Python):
N,H=map(int,input().split())
c=[list(map(int,input().split()))for _ in[0]*N]
a=max(r[0]for r in c)
b=sorted(r[1]for r in c if r[1]>a)
n=0
while H>0 and b:
    H-=b.pop()
    n+=1
print(n+max(H-1,-1)//a+1)

Solution (Python):
import math

N, H = map(int, input().split())
kiri = []
nage = []
for n in range(N):
    tmps = list(map(int, input().split()))
    kiri.append(tmps[0])
    nage.append(tmps[1])

kiri_max = max(kiri)
nage.sort(reverse=True)
nage = list(filter(lambda x: x >= kiri_max, nage))

count = 0
while (H > 0):
    if (len(nage) != 0):
        H -= nage[0]
        nage.pop(0)
        count += 1
    else:
        if ( H % kiri_max == 0):
            count += H // kiri_max
        else:
            count += H // kiri_max + 1
        break

print(count)

Solution (Python):

import math
N, H = map(int, input().split())

a = []
b = []
for i in range(N):
    t1, t2= map(int, input().split())
    a.append(t1)
    b.append(t2)

mx = max(a)
b = sorted(b, reverse=True)
count = 0
attack = 0
for i in range(N):
    if mx >= b[i] or attack >= H:
        break
    count += 1
    attack += b[i]

if attack < H:
    count += math.ceil((H - attack) / mx)

print(count)

Solution (Python):
N, H = map(int, input().split(" "))
a = []
b = []
for i in range(N):
  c, d = map(int, input().split(" "))
  a.append(c)
  b.append(d)
  
amax = max(a)
b.sort()
b.reverse()
bf = [x for x in b if x > amax]

count = 0
judge = 0
for i in bf:
    H -= i
    if H <= 0:
        judge = 1
        count += 1
        print(count)
        break
    count += 1

if judge != 1:
    e = H//amax
    f = H%amax
    if f != 0:
        e += 1
    print(count+e)

Solution (Python):

""" abc085d """

import math

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

maxA = max(katanaA)
throwKatanaB = [k for k in katanaB if k > maxA]
throwKatanaB.sort(reverse=True)
count = 0
for t in throwKatanaB:
    h -= t
    count += 1
    if h <= 0:
        break
if h <= 0:
    print(count)
else:
    count += int(math.ceil(h / maxA))
    print(count)

Solution (Python):
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())

a_max = max(a)
b.sort(reverse=True)

c = 0
for i in range(N):
    if b[i] > a_max:
        H -= b[i]
        c += 1
    if H <= 0:
        break

if H > 0:
    c += (H + a_max - 1) // a_max

print(c)

Solution (Python):
import math
import numpy as np
from operator import mul



















N, H = map(int, input().split())

D = [list(map(int, input().split())) for i in range(N)]
B = [D[i][1] for i in range(N)] 

a_max = 0 

for i in range(N):
    if D[i][0] >= a_max:
        a_max = D[i][0]

B_larger = [] 

for i in range(N):
    if B[i] > a_max:
        B_larger.append(B[i])

B_larger.sort(reverse=True)

n = 0

for i in range(len(B_larger)):
    H = H - B_larger[i]
    n += 1    
    if H <= 0:
        print(n)
        break
    

if H > 0:
    n += math.ceil(H/a_max)
    print(n)

Solution (Python):
N, H = input().strip().split(' ')
N, H =[int(N),int(H)]
L =list()
for i in range(0,N):
    X, Y = input().strip().split(' ')
    X, Y =[int(X), int(Y)]
    L.append([X,Y])

L0 = list()
for i in range(0,N):
    L0.append(L[i][0])

L1 = list()
for i in range(0,N):
    L1.append(L[i][1])

M = max(L0)
L2 = list()

for i in range(0,N):
    if L1[i] > M:
        L2.append(L1[i])

L2 = sorted(L2)

L2 = L2[::-1]

count = 0

for i in range(0,len(L2)):
    if H > 0:
        H -= L2[i]
        count += 1
        if H <= 0:
            print(count)

if H > 0:
    if H % M == 0:
        count += H//M
        print(count)
    else:
        count = count + H//M + 1
        print(count)

Solution (Python):
import math
N = 5
H = 500
N,H = map(int,input().split())
As = []
Bs = []
for i in range(N):
    a,b = map(int,input().split())
    As.append(a)
    Bs.append(b)
A_max = max(As)
Bs_select = []
for b in Bs:
    if(b>A_max):
        Bs_select.append(b)
if(sum(Bs_select) < H):
    print(len(Bs_select) + math.ceil((H-sum(Bs_select))/A_max))
else:
    Bs_select.sort(reverse=True)
    S = 0
    cnt = 0
    for b in Bs_select:
        S += b
        cnt += 1
        if(S >= H):
            print(cnt)
            break

Solution (Python):
N, H = input().strip().split(' ')
N, H =[int(N),int(H)]
L =list()
for i in range(0,N):
    X, Y = input().strip().split(' ')
    X, Y =[int(X), int(Y)]
    L.append([X,Y])

L0 = list()
for i in range(0,N):
    L0.append(L[i][0])

L1 = list()
for i in range(0,N):
    L1.append(L[i][1])

M = max(L0)
L2 = list()

for i in range(0,N):
    if L1[i] > M:
        L2.append(L1[i])

L2 = sorted(L2)
L2.reverse()
count = 0

for i in range(0,len(L2)):
    if H > 0:
        H -= L2[i]
        count += 1
        if H <= 0:
            print(count)

if H > 0:
    if H % M == 0:
        count += H//M
        print(count)
    else:
        count = count + H//M + 1
        print(count)

Solution (Python):
from math import ceil
n,h = map(int,input().split())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i] , b[i] = map(int,input().split())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] > ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)

Solution (Python):
l0 = input().split(' ')
N = int(l0[0])
H = int(l0[1])
L = []
i=0
while i < N:
    l1 = input().split(' ')
    l2 = [int(l1[0]), int(l1[1])]
    L.append(l2)
    i += 1
L.sort(key = lambda x:x[1])

L2 = L.copy()
L2.sort()
Amax = L2[N-1][0]
p=N-1
while p >= 0:
    if L[p][1] > Amax:
        p -= 1
    else:
        break
k=N-1
Btot = 0
c=0
counter = 0
while k > p:
    H -= L[k][1]
    k -= 1
    counter += 1
    if H <= 0:
        c = counter
        break

st =  H // Amax
counter += st
if st * Amax != H:
    counter += 1
if c ==0:
    print(counter)
else:
    print(c)

Solution (Python):
import math
N,H = input().split()
n = int(N)
h = int(H)
da = 0
db = [0] * n
for i in range(n):
    a,b = tuple(map(int,input().split()))
    da = max(a,da)
    db[i] = b
db.sort()      


total = 0 
i = 0
while total < h:
    if db[-1] >= da:
        total += db.pop()
        if len(db) == 0:
            i += math.ceil((h - total)/da) + 1
            break
    else:
        i += math.ceil((h - total)/da) 
        break
    i += 1
print(str(i))

Solution (Python):
def main():
    n,h = map(int,input().split())
    a,b = [],[]
    for i in range(n):
        x,y = map(int,input().split())
        a.append(x)
        b.append(y)

    max_a = max(a)
    b.sort()
    b.reverse()

    now = 0
    ans = 0
    for i in range(n):
        now += max(b[i],max_a)
        ans += 1
        if now>=h:
            return ans

    rem = h-now
    ans += (rem+max_a-1)//max_a
    return ans

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

Solution (Python):

N, H = map(int, input().split(" "))
a = []
b = []

for i in range(N):
  c, d = map(int, input().split(" "))
  a.append(c)
  b.append(d)
  
amax = max(a)
b.sort()
b.reverse()
bf = [x for x in b if x > amax]

count = 0
judge = 0
for i in bf:
    H -= i
    if H <= 0:
        judge = 1
        count += 1
        print(count)
        break
    count += 1

if judge != 1:
    sho = H//amax
    amr = H%amax
    if amr != 0:
        sho += 1
    print(count+sho)

Solution (Python):
import sys
N,H=map(int,input().split(' '))
mdmg=0
mth=0
th=[]
for i in range(N):
  a,b=map(int,input().split(' '))
  if mdmg==a and mth>=b:
    th.append(mth)
    mth=b
  elif mdmg<a: 
    mdmg=a
    th.append(mth)
    mth=b
  else: th.append(b)
th.sort()
th.reverse()
count=0
for i in th:
  if(i>=H or mth>=H):
    count+=1
    print(count)
    sys.exit()
  elif i<mdmg:
    break
  else:
    count+=1
    H-=i
if mdmg>mth: mth=mdmg
H-=mth
if H%mdmg==0:
  count+=int(H/mdmg)+1
else:
  count+=int(H/mdmg)+2
print(count)

Solution (Python):
import sys
N,H=map(int,input().split(' '))
mdmg=0
mth=0
th=[]
for i in range(N):
  a,b=map(int,input().split(' '))
  if mdmg==a and mth>=b:
    th.append(mth)
    mth=b
  elif mdmg<a: 
    mdmg=a
    th.append(mth)
    mth=b
  else: th.append(b)
th.sort()
th.reverse()
count=0
for i in th:
  if(i>=H or mth>=H):
    count+=1
    print(count)
    sys.exit()
  elif i<mdmg:
    break
  else:
    count+=1
    H-=i
if mdmg>mth: mth=mdmg
H-=mth
if H%mdmg==0:
  count+=int(H/mdmg)+1
else:
  count+=int(H/mdmg)+2
print(count)

Solution (Python):
N, H = map(int, input().split())
a, b = [0] * N, [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())
ma = max(a)
b.sort(reverse=True)
ans = 0
index = 0
while H > 0 and len(b) > index and b[index] > ma:
    H -= b[index]
    index += 1
    ans += 1
if H > 0:
    ans += (H + ma - 1) // ma
print(ans)

Solution (Python):
import sys
import math

(N, H) = tuple(map(int, input().split(" ")))

a = []
b = []
result = 0

for i in range(N):
    (ai,bi) = tuple(map(int, input().split(" ")))
    a.append(ai)
    b.append(bi)

a_max = max(a)
b.sort()
b.reverse()
b_length = len(b)

for i, bi in enumerate(b):
    if bi < a_max:
        b_length = i
        break


S = 0

for l in range(b_length):
    S += b[l]
    if S >= H:
        result = l + 1
        print(result)
        sys.exit()


result = b_length + int(math.ceil((H - S)/a_max))

print(result)

Solution (Python):

N, H = list(map(int, input().split()))
a = []
b = []
for i in range(N):
    ai, bi = list(map(int, input().split()))
    a.append(ai)
    b.append(bi)

a_max = max(a) 
b_dmg = [ elem for elem in b if elem > a_max]

cnt = 0
isFinished = False
for elem in (reversed(sorted(b_dmg))):
    H -= elem
    cnt += 1
    if H <= 0:
        print(cnt)
        isFinished = True
        break

if isFinished == False:
    if H % a_max == 0:
        print(int(H/a_max)+len(b_dmg))
    else:
        print(int(H/a_max)+1+len(b_dmg))

Solution (Python):
import math

inn = [int(x) for x in input().split()]
aa = []
bb = []
for i in range(inn[0]):
    tmp = [int(x) for x in input().split()]
    aa.append(tmp[0])
    bb.append(tmp[1])

maxaa = max(aa)
ba = [x for x in bb if x > maxaa]
sumba = sum(ba)
lenba = len(ba)
if sumba == inn[1]:
    print(lenba)
    exit()
elif sumba > inn[1]:
    count = lenba
    tot = sumba
    for b in sorted(ba):
        tot -= b
        if tot < inn[1]:
            print(count)
            exit()
        count -= 1
else:
    count = lenba + math.ceil((inn[1]-sumba)/max(aa))
    print(count)

Solution (Python):
import re
import math
def comb(n, r):
    if n == 0 or r == 0:
        return 1
    return int(comb(n, r-1) * (n-r+1) / r)

if __name__ == '__main__':
    
    N, H = [int(x) for x in input().split()]
    A = []
    B = []
    for i in range(N):
        ta, tb = [int(x) for x in input().split()]
        A.append(ta)
        B.append(tb)

    B = sorted(B)
    B.reverse()
    maxA = max(A)

    cntAtk = 0
    dmg = 0
    for b in B:
        if b <= maxA:
            break
        cntAtk += 1
        dmg += b
        if dmg >= H:
            print(cntAtk)
            exit()

    cntAtk += math.ceil((H-dmg) / maxA)
    print(cntAtk)

Solution (Python):
from math import ceil
n, h = map(int, raw_input().split())
s = []
for x in xrange(n):
    ta, tb = map(int, raw_input().split())
    s.extend([(ta, 1), (tb, 0)])
s.sort(key = lambda _: _[0], reverse = True)
att = 0
for i, _ in enumerate(s):
    if att >= h or _[1]:
        cnt = i
        break
    att += _[0]
print cnt + int(ceil(float(h - att) / max([_[0] for _ in s if _[1]]))) if att < h else cnt

Solution (Python):
N, H = map(int,input().split())
damage_low = [0 for i in range(0,N)]
damage_high = [0 for i in range(0,N)]
count = 0

for i in range(0,N):
    a, b = map(int,input().split())
    damage_low[i] = a
    damage_high[i] = b

damage_low.sort()  
damage_high.sort()

for i in range(0,N):  
    if damage_high[N-1-i] > damage_low[N-1]:  

        H = H - damage_high[N-1-i]  
        count += 1
    if H <= 0:  
        break

while H > 0:  
    if H % damage_low[N-1] == 0:
        count = count + (H // damage_low[N-1])
        break
    else:
        count = count + (H // damage_low[N-1]) + 1
        break

print(count)

Solution (Python):
import math
n,h = map(int,input().split())
ab = [input() for i in [0]*n]
amax = max([int(x.split()[0]) for x in ab])
b = sorted([int(x.split()[1]) for x in ab if int(x.split()[1])>amax])
if sum(b) < h:
    print(math.ceil((h-sum(b))/amax)+len(b))
else:
    b.reverse()
    for i in range(len(b)):
        h -= b[i]
        if h <=0:
            print(i+1)
            break

Solution (Python):
import sys

num, hp = (int(i) for i in input().split(" "))

katanas_a = []
katanas_b = []

for i in range(num):
    a, b = (int(j) for j in input().split(" "))
    katanas_a.append(a)
    katanas_b.append(b)

katanas_a.sort()
swing_max = katanas_a[len(katanas_a) - 1]

katanas_b.sort()

attack_count = 0
for katana in reversed(katanas_b):
    if katana > swing_max:
        hp -= katana
        attack_count += 1

    if hp <= 0:
        print(attack_count)
        sys.exit()

if hp % swing_max != 0:
    attack_count += int(hp / swing_max) + 1
else:
    attack_count += int(hp / swing_max)

print(attack_count)

Solution (Python):
N, H = map(int, input().split(' '))
katana = [map(int, input().split(' ')) for _ in range(N)]
dmg_wield, dmg_throw = zip(*katana)

dmg_wield_max = max(dmg_wield)
dmg_throw = sorted([d for d in dmg_throw if d > dmg_wield_max])

n = 0
while H > 0 and dmg_throw:
    H -= dmg_throw.pop()
    n += 1

print(n + max(H-1, -1) // dmg_wield_max + 1)

Solution (Python):
N,H=map(int,input().split())
c=[list(map(int,input().split()))for _ in[0]*N]
a=max(r[0]for r in c)
b=sorted(r[1]for r in c if r[1]>a)
n=0
while H>0 and b:
    H-=b.pop()
    n+=1
print(n+max(H-1,-1)//a+1)

Solution (Python):

from math import ceil
n,h=[int(i)for i in input().split()]
ab=[[int(i) for i in input().split()] for j in range(n)]
ans=0


a=[ab[i][0] for i in range(n)]
b=[ab[i][1] for i in range(n)]
a.sort()
b.sort()
while h>0 and len(b)>0 and b[-1]>a[-1]:
        h-=b[-1]
        b.pop(-1)
        ans+=1
if h>0:
        ans+=int(ceil(h/a[-1]))
print(ans)

Solution (Python):
N,H=map(int,raw_input().split())
c=[]
for i in range(N):
	a,b=map(int,raw_input().split())
	c.append((a,0))
	c.append((b,1))

c.sort(key=lambda x:x[0],reverse=True)

cnt=0
for i,j in c:
	if j==1:
		H-=i
		cnt+=1
		if H<=0:
			break
	else:
		if H%i==0:
			cnt+=H/i
			break
		else:
			cnt+=H/i+1
			break
print cnt

Solution (Python):



N,H=[int(i) for i in input().split()]

a = [0 for i in range(N)]
b = [0 for i in range(N)]
ll = []
for i in range(N):
    x,y=([int(i) for i in input().split()])
    ll.append([x,y])
    a[i] = x
    b[i] = y
amax = max(a)
bmax = max(b)

lll=sorted(ll,key=lambda x: x[1])


amaxind = [i for i in range(N) if lll[i][0] == amax]


c=0
while H > 0:
    if len(lll) > 0 and lll[-1][1] > amax:
        X = lll.pop()
        H -= X[1]
        c +=1
      
    else:
        num = (H-1)//amax
        H = -1
        c += num+1
    
print(c)

Solution (Python):

import math

N, H = list(map(int, input().split()))

la, lb = [], []

for i in range(N):
    a, b = list(map(int, input().split()))
    la.append(a)
    lb.append(b)

lb = sorted(lb, reverse=True)
ma, c = max(la), 0

for d in lb:
    if d < ma or H <= 0:
        break
    H -= d
    c += 1

if H > 0:
    c += math.ceil(H / ma)

print(c)

Solution (Python):
ip = input().split()
N = int(ip[0])
H = int(ip[1])
amax = 0
ans = 0
b = []
for i in range(N):
    ip = input().split()
    a = int(ip[0])
    amax = max(amax, a)
    b.append(int(ip[1]))
b.sort()
b.reverse()
for x in b:
    if(amax>=x or H <= 0):
        break
    else:
        ans = ans + 1
        H = H - x
if(H > 0):
    ans = int(ans + (H + amax - 1)/amax)
print(ans)

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

max_A=max(A)

D=[]
for i in range(N):
  if B[i]>max_A:
    D.append(B[i])
D.sort(reverse=True)

ans=0
for i in range(len(D)):
  H-=D[i]
  ans+=1
  if H<=0:
    break

if H>0:
  if H%max_A==0:
    ans+=int(H/max_A)
  else:
    ans+=(int(H/max_A)+1)

print(ans)

Solution (Python):
import math
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

amax = max(A)

B = list(filter(lambda x: x > amax, B))
B.sort()

ans = 0
while H > 0:
    
    if B:
        H -= B.pop()
    
    else:
        ans += math.ceil(H/amax)
        break
    ans += 1

print(ans)

Solution (Python):
import math
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

amax = max(A)

B = list(filter(lambda x: x > amax, B))
B.sort(reverse=True)

ans = 0
while H > 0:
    
    if not B == []:
        H -= B[0]
        del B[0]
    
    else:
        ans += math.ceil(H/amax)
        break
    ans += 1

print(ans)

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

nocost = max(A)
B.sort()

ans = 0
while H > 0:
  if B:
    atk = B.pop(-1)
    if atk > nocost:
      H -= atk
      ans +=1
    else: 
      ans += (H+nocost-1)//nocost
      H -= nocost*(H+nocost-1)//nocost
  else:
    ans += (H+nocost-1)//nocost
    H -= nocost*(H+nocost-1)//nocost

print(ans)

Solution (Python):

from bisect import bisect, bisect_left, insort
from itertools import accumulate
def inpl(): return tuple(map(int, input().split()))

N, H = inpl()
T = sorted([inpl() for _ in range(N)], reverse=True)
mta, mtb = T[0]
sT = sorted([t[1] for t in T[1:]])
sT = sT[bisect(sT, mta):] 

S = sum(sT)
if S + mtb >= H: 
    insort(sT, mtb)
    A = list(accumulate(sT[::-1]))
    print(bisect_left(A, H)+1)
else:
    print(len(sT) + 1 + ((H-S-mtb)//mta + ((H-S-mtb)%mta!=0)))

Solution (Python):

n, h = map(int, input().split())

a = [0 for _ in range(0, n)]
b = [0 for _ in range(0, n)]

for i in range(n):
    aa, bb = map(int, input().split())
    a[i] = aa
    b[i] = bb

a_max = max(a)

b = sorted(b, reverse=True)

res = 0
for hits in b:
    if hits < a_max:
        break
    h -= hits
    res += 1
    if h <= 0:
        h = 0
        break

res += (h + a_max - 1) // a_max

print(res)

Solution (Python):
n, h = map(int, input().split())
ab = [tuple(map(int, input().split())) for _ in range(n)]
ans = 0
bs = []
maxa = 0
for a, b in ab:
    if a < b:
        bs.append(b)
    maxa = max(a, maxa)
bs = list(reversed(sorted(bs)))
d = 0
for b in bs:
    if h <= d:
        break
    elif maxa < b:
        d += b
        ans += 1
    else:
        break
if d < h:
    ans += (h - d + maxa - 1) // maxa
print(ans)