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):
from math import ceil


def solve(s):
    n, h, *ab = map(int, s.split())
    max_a = max(ab[::2])
    *b, = filter(lambda x: x > max_a, ab[1::2])
    if sum(b) >= h:
        b = sorted(b)
        ans = 0
        while h > 0:
            h -= b.pop()
            ans += 1
        return ans
    else:
        return len(b) + ceil((h - sum(b)) / max_a)


n, m = map(int, input().split())
print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))

Solution (Python):
from functools import reduce
from math import ceil


N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))


m = max(a)
c = sorted(
    filter(lambda x: x > m, b),
    reverse=True
)
ans, _ = (
    reduce(
        lambda acc, e:
            (acc[0] + 1, acc[1] + e) if acc[1] < H else
            acc,
        c,
        (0, 0)
    ) if sum(c) >= H else
    (len(c) + ceil((H - sum(c)) / m), 0)
)


print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n,h = map(int,input().split())
ab = []
cnt = 0
max_a = 0

for i in range(n):
  a,b = map(int,input().split())
  ab += [[a,b]]
ab.sort(reverse=True)
max_a = ab[0][0]
ab.sort(key=lambda x: x[1],reverse=True)

for i in range(n):
  if ab[i][1] > max_a:
    h -= ab[i][1]
    cnt += 1
  else:
    break
  if h <= 0:
    print(cnt)
    exit()
cnt += -(-h // max_a)
print(cnt)

Solution (Python):
import math
def solve():
    N, H = map(int, input().split())
    katana = []
    for i in range(N):
        a, b = map(int, input().split())
        katana.append((a, 0, i))
        katana.append((b, 1, i))
    katana = sorted(katana, reverse = True)
    ans = 0
    for i in range(N*2):
        k = katana[i]
        
        if H<=0:
            return ans
        if k[1]==0:
            break
        H-=k[0]
        ans+=1
    return ans+math.ceil(H/k[0])
print(solve())

Solution (Python):
import sys
import math
N,H=map(int,input().split())
p=[]
x=[list(map(int,input().split())) for i in range(N)]
a=max(x[i][0] for i in range(N))
for i in range(N):
    if x[i][1]>a: p.append(x[i][1])

p.sort(reverse=True)
for i in range(len(p)):
    H-=p[i]
    if H<=0: print(i+1),sys.exit()

print(len(p)+math.ceil(H/a))

Solution (Python):
from functools import reduce
import math

def main():
    
    
    
    

    
    
    
    
    
    

    
    

    
    
    
    
    
    
    
    
    
    INF = float("inf")

    
    MOD = 10**9+7
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    N,H = (int(_) for _ in input().split())
    a = []
    b = []
    for i in range(N):
        s1,s2 = (int(_) for _ in input().split())
        a.append(s1)
        b.append(s2)
    a_max = max(a)
    b.sort()
    b = b[::-1]
    ans = 0
    
    i = 0
    while i<N:
        if(b[i]<=a_max):
            break
        if(H<=0):
            break
        ans += 1
        H -= b[i]
        i += 1
    if H>0:
        ans += math.ceil(H/a_max)
    print(ans)
    
if __name__ == '__main__':
    main()

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

ab.sort(key = lambda x: x[1], reverse = True)

ma = max(ab, key = lambda x: x[0])[0]
ans = 0
for i in range(N):
  if ab[i][1] > ma:
    H -= ab[i][1]
    ans += 1
  else:
    ans += (H - 1) // ma + 1
    break
  if H <= 0:
    break
else:
  ans += (H - 1) // ma + 1

print(ans)

Solution (Python):
import numpy as np

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

swing = sorted([AB[i][0] for i in range(N)], reverse=True)
throw = sorted([AB[i][1] for i in range(N)], reverse=True)

cnt = 0

if throw[0] > swing[0]:  
  big_throw = [throw[i] for i in range(N) if throw[i] > swing[0]]
  throw_cumsum = np.array(big_throw).cumsum()
  for i in range(len(big_throw)):
    if H - throw_cumsum[i] <= 0:
      print(i+1)
      exit()
  else:
    cnt += len(throw_cumsum)
    H -= throw_cumsum[-1]


cnt += ((H + (swing[0]-1)) // swing[0])
print(cnt)

Solution (Python):
import math

def main():
    num, hp = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]
    data_a = [data[i][0] for i in range(num)]
    data_b = [data[i][1] for i in range(num)]
    data_a.sort(reverse=True)
    data_b.sort(reverse=True)
    count = 0
    huru = data_a[0]
    nageru_ind = 0
    while hp > 0:
        if nageru_ind == num:
            count += math.ceil(hp / huru)
            break
        elif huru > data_b[nageru_ind]:
            count += math.ceil(hp / huru)
            break
        else:
            hp -= data_b[nageru_ind]
            nageru_ind += 1
        count += 1


    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
import math

def main():
    num, hp = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(num)]
    data_a = [data[i][0] for i in range(num)]
    data_b = [data[i][1] for i in range(num)]
    data_a.sort(reverse=True)
    data_b.sort(reverse=True)
    count = 0
    huru = data_a[0]
    nageru_ind = 0
    while hp > 0:
        if nageru_ind == num:
            count += math.ceil(hp / huru)
            break
        elif huru > data_b[nageru_ind]:
            count += math.ceil(hp / huru)
            break
        else:
            hp -= data_b[nageru_ind]
            nageru_ind += 1
        count += 1


    print(count)


if __name__ == '__main__':
    main()

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

A=sorted(A,key=lambda x:x[0],reverse=True)
count=0
for i in range(2*N):
    if A[i][1]=="a":
        if H%A[i][0]==0:
            count+=H//A[i][0]
        else:
            count+=H//A[i][0] + 1
        H=0
    else:
        H-=A[i][0]
        count+=1
    if H<=0:
        break

print(count)

Solution (Python):
n, h, *t=map(int,open(0).read().split())
a = t[::2]
b = t[1::2]
ma = max(a)
b_high = [i for i in b if i > ma]
if sum(b_high) > h:
  ans = 0
  b_high = sorted(b_high)
  while h > 0:
    h = h - b_high.pop()
    ans += 1
  print(ans)
else:
  if (h - sum(b_high)) % ma == 0:
    print(len(b_high) + (h - sum(b_high)) // ma)
  else:
    print(len(b_high) + ((h - sum(b_high)) // ma) + 1)

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

A = sorted([ab[0] for ab in AB])
B = sorted([ab[1] for ab in AB])
aMax = A[-1]
import bisect
b = bisect.bisect_left(B, aMax)
sumB = sum(B[b:])
ans = 0
i = 0

if sumB < H:
    ans += N-b
    H -= sumB
    if H % aMax == 0:
        ans += H // aMax
    else:
        ans += H // aMax + 1
else:
    while H > 0:
        if N-i-1 >= b:
            H -= B[-(i+1)]
            i += 1
            ans += 1
        else:
            if H % aMax == 0:
                ans += H // aMax
            else:
                ans += H // aMax + 1

print(ans)

Solution (Python):
throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h>0 and throw and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)

Solution (Python):
a = []
b = []
N,H = map(int,input().split())
for i in range(N):
    ca,cb = map(int,input().split())
    a.append(ca)
    b.append(cb)
count = 0
ma = max(a)
b.sort(reverse = True)
def ans():
    global N,H,count
    for i in range(N):
        if b[i] < ma:
            break
        H -= b[i]
        count += 1
        if H <= 0:
            return count
    count += H//ma
    if H%ma != 0:
        count += 1
    return count
print(ans())

Solution (Python):
import heapq

N, H = map(int, input().split())
katana = [list(map(int, input().split())) for _ in range(N)]

TYPE_A = 0
TYPE_B = 1

powers = []
for i in range(N):
    heapq.heappush(powers, (-katana[i][1], i, TYPE_B))

ans = 0
while H > 0:
    power, idx, t = heapq.heappop(powers)
    power = -power
    if t == TYPE_A:
        ans += (H - 1) // power + 1
        break
    else:
        H -= power
        heapq.heappush(powers, (-katana[idx][0], idx, TYPE_A))
        ans += 1

print(ans)

Solution (Python):
import math
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)
As.sort()
Bs.sort()
amax = As[-1]
ans = 0
dam = 0
while Bs:
    b = Bs.pop()
    if b < amax or dam >= H:
        break
    else:
        ans += 1
        dam += b
if dam < H:
    ans += math.ceil((H-dam)/amax)
print(ans)

Solution (Python):
import math
N, H = map(int, input().split())
sword =[list(map(int, input().split())) for _ in range(N)]
def f1(l):
    a, b = l
    return a
def f2(l):
    a, b = l
    return b
sword.sort(key = f2)
sword.sort(key = f1)
amax, b1 = sword[-1]
sword.sort(key = f2)
dam = 0
ans = 0
while sword:
    a, b = sword.pop()
    if b < amax:
        break
    else:
        dam += b
        ans += 1 
        if dam >= H:
            break
if dam < H:
    dam -= b1
    ans -= 1
    ans += max(math.ceil((H-dam-b1)/amax), 0) + 1
print(ans)

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

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

Solution (Python):
N,H=map(int,input().split())
L=[list(map(int,input().split())) for _ in range(N)]
A=max(a for a,_ in L)
B=sorted(b for _,b in L if b>A)
M=len(B)
while B and H>0:
    H-=B.pop()
print(M-len(B)+max(-1,H-1)//A+1)

Solution (Python):
N, H = [int(i) for i in input().split()]
L = [[int(i) for i in input().split()] for _ in range(N)]
A = max(a for a, _ in L)
B = sorted(b for a, b in L if b > A)
M = len(B)
while B and H > 0:
    H -= B.pop()
print(M - len(B) + max(-1, H - 1) // A + 1)

Solution (Python):
import math
N, H = (int(x) for x in input().split())
list = []
for i in range(N):
    list.append([int(x) for x in input().split()])

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

joint_list.sort(key = lambda x: x[0])
total_damage, ans, index = 0, 0, 2*N-1
while total_damage < H:
    if joint_list[index][1] == 1:
        total_damage += joint_list[index][0]
        index -= 1
        ans += 1
    else:
        ans += math.ceil((H - total_damage) / joint_list[index][0])
        break

print(ans)

Solution (Python):



N,H = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = zip(*AB)

a = max(A) 
B = [b for b in B if b > a] 
B.sort(reverse = True)

answer = 0
hp = H
attack_cnt = 0

for b in B:
  if hp <= 0:
    break
  attack_cnt += 1
  hp -= b

if hp > 0:
  attack_cnt += (hp-1)//a + 1

print(attack_cnt)

Solution (Python):
N, H = map(int,input().split())
S = []
for i in range(N):
	S.append(list(map(int, input().split())))
tS = list(zip(*S))
A = tS[0]
B = tS[1]
maxA = max(A)
usB = [k for k in B if k > maxA]
BBB = sorted(usB, reverse = True)
cnt = 0
for b in BBB:
	H -= b
	cnt += 1
	if H <= 0:
		break
if H <= 0:
	print(cnt)
else:
	print(cnt + (H - 1)//maxA + 1)

Solution (Python):
from operator import itemgetter
import math
N,H = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()]for _ in range(N)]
ab.sort(key = itemgetter(1),reverse = True)
left = H
cnt = 0
max_a = max(ab,key=itemgetter(0))[0]

for i in ab:
    if(i[1]>max_a):
        left -= i[1]
        cnt += 1
    else:
        cnt += math.ceil(left/max_a)
        left = 0
        break
    
    if(left<=0):
        break
        
if(left>0):
    cnt += math.ceil(left/max_a)
print(cnt)

Solution (Python):
import math

def solve(h, alist, blist):
    amax = max(alist)
    c = 0
    for b in sorted(blist, reverse=True):
        if b <= amax:
            break
        c += 1
        h -= b
        if h <= 0:
            return c
    return c + math.ceil(h / amax)
 
 
n, h = map(int, input().split())
alist, blist = [], []
for _ in range(n):
    a, b = map(int, input().split())
    alist.append(a)
    blist.append(b)
 
print(solve(h, alist, blist))

Solution (Python):
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]

a_all = [_ab[0] for _ab in ab]
b_all = [_ab[1] for _ab in ab]

a_max = max(a_all)

b_all_useful = []
for b in b_all:
    if b > a_max:
        b_all_useful.append(b)

b_all_useful.sort()

useful_sum = sum(b_all_useful)
if useful_sum > h:
    counter = 0
    i = 0
    while True:
        counter += b_all_useful[-1 * (i + 1)]
        i += 1
        if counter >= h:
            break
    print(i)

else:
    h_new = h - useful_sum
    import math
    print(math.ceil(h_new / a_max) + len(b_all_useful))

Solution (Python):
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=0
arr=sorted(arr,key=lambda x:x[0],reverse=True)
amax=arr[0][0]
arr=sorted(arr,key=lambda x:x[1],reverse=True)
bsum=0
for i in range(n):
  if amax>=arr[i][1]:
    break
  bsum+=arr[i][1]
  ans+=1
  if bsum>=k:
    break
if bsum>=k:
  print(ans)
else:
  if (k-bsum)%amax==0:
    ans+=(k-bsum)//amax
  else:
    ans+=(k-bsum)//amax+1
  print(ans)

Solution (Python):
import math
n, h = map(int, input().split())

a_max = 1
b = [0] * n
tmp = 0
for i in range(n):
  tmp, b[i] = map(int, input().split())
  if a_max < tmp: a_max = tmp
    
b.sort(reverse = True)
sum_b = 0
cnt_swing = 0
cnt_throw = 0
cnt_min = 10 ** 9
for i in range(n):
  sum_b += b[i]
  cnt_swing = i+1
  if h - sum_b <= 0:
    cnt_throw = 0
  else:
    cnt_throw = int(math.ceil((h-sum_b) / a_max))
  if cnt_swing + cnt_throw < cnt_min:
    cnt_min = cnt_swing + cnt_throw
    
    
print(cnt_min)

Solution (Python):

from math import *
N,H=map(int,raw_input().split())
A=[];B=[]
for i in range(N):
    a,b=map(int,raw_input().split())
    A.append(a);B.append(b)
am=max(A)
B.sort()
B.reverse()
B.append(-1)
h=0
c=0
bi=0
while h<H:
    b=B[bi]
    if b<am:
        c+=int(ceil((H-h)*1.0/am))
        break
    else:
        h+=b
        c+=1
        bi+=1
print(c)

Solution (Python):
from math import ceil
import sys
input=sys.stdin.readline
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort()

ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[-1]< m:
    break
  h-=b.pop()
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Solution (Python):
from math import ceil
import sys
input=sys.stdin.readline
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
while(h>0 and len(b) != 0):
  if b[0] < m:
    break
  h-=b[0]
  b.pop(0)
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Solution (Python):
from math import ceil
n, h = map(int, input().split())
a = []
b = []
for i in range(n):
  p, q = map(int, input().split())
  a.append(p)
  b.append(q)
b.sort(reverse=1)
ans=0
m=max(a)
for i in b:
  if i < m or h<=0:
    break
  h-=i
  ans+=1
if h>0:
  ans+=ceil(h/m)
print(ans)

Solution (Python):
def main():
    import sys
    from math import ceil
    input = sys.stdin.readline

    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)
    a_max = max(A)
    B.sort(reverse=True)
    ans = 0
    for i in range(N):
        if a_max >= B[i]:
            break
        elif H > 0:
            ans += 1
            H -= B[i]
            continue
    if H > 0:
        ans += ceil(H / a_max)
    print(ans)


if __name__ == '__main__':
    main()

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

Solution (Python):
N,H=map(int, input().split())
ab=[list(map(int,input().split())) for i in range(N)]
ab=sorted(ab,key=lambda x: x[1],reverse=True)
best=0
throw=0
damage=0
for a,b in ab:
    best=max(best,a)
    if b<best:
        break
    throw+=1
    damage+=b
    if damage>=H:
        break
import math
slash=max(0,math.ceil((H-damage)/best))
print(slash+throw)

Solution (Python):
N, H = map(int, input().split(' '))

maxA = 0
bs = []
for _ in range(N):
    a, b = map(int, input().split(' '))
    bs.append(b)
    if maxA < a:
        maxA = a

bs = list(filter(lambda x: maxA < x, bs))
bs.sort()

cnt = 0
while H > 0 and bs:
    cnt += 1
    H -= bs.pop()

if H > 0:
    cnt += H // maxA
    if H % maxA:
        cnt += 1

print(cnt)

Solution (Python):
N,H = [ int(it) for it in input().split() ]
li = [ [int(it) for it in input().split() ] for i in range(N) ]

go = []
for a,b in li:
  go.append( (a,False) )
  go.append( (b,True) )
go.sort( key = lambda x:x[0] )

go.reverse()

s = 0
h = H
for c,flag in go:
  if (h<=0):
    break
  if (flag):
    h -= c
    s += 1
  else:
    kai = (h+c-1)//c
    h -= c*kai
    s += kai
print ( s )

Solution (Python):
import math
import sys

sys.setrecursionlimit(10000)
INF = float('inf')

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

B.sort()
amax = max(A)

hp = H
cnt = 0
for i in reversed(range(N)):
    if B[i] < amax or hp <= 0:
        break
    hp -= B[i]
    cnt += 1
cnt += max(0, math.ceil(hp / amax))

print(cnt)

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)
ma=max(A)
BB=[]
for i in range(n):
  if B[i]>ma:
    BB.append(B[i])
BB.sort(reverse=True)
count=0
dmg=0
while dmg<h:
  if count<len(BB):
    dmg+=BB[count]
    count+=1
  else:
    r=(h-dmg-1)//ma+1
    dmg=h
    count+=r
print(count)

Solution (Python):
from math import ceil
N, H = map(int, input().split())
a = [list(map(int, input().split()))for _ in range(N)]
a.sort(key=lambda x: x[1], reverse=True)
s = 0
ans = 0
m = max(a, key=lambda x: x[0])[0]
for n in a:
    if m < n[1]:
        s += n[1]
        ans += 1
        if s >= H:
            break
else:
    ans += ceil((H - s) / max(a, key=lambda x: x[0])[0])
print(ans)

Solution (Python):
import math
from operator import itemgetter

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

m = max(a)[0]

a.sort(key=itemgetter(1))
a.reverse()
i = 0
ans = 0
while a[i][1] > m:
    h-=a[i][1]
    ans +=1
    i+=1
    if h<=0:
        break
    if i==n:
        break

print(ans+math.ceil(max(h,0)/m))

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

cnt=0
for b in B:
 if A[0] < b:
  H-=b
  cnt+=1
 else:break
 if H<=0:break
print(cnt+((H//A[0])+(H%A[0]!=0)if H>0 else 0))

Solution (Python):
N,HP=map(int,input().split())
As=[0]*N
Bs=[0]*N
for i in range(N):
 a,b=map(int,input().split())
 As[i]=a
 Bs[i]=b
As.sort(reverse=True)
Bs.sort(reverse=True)

cnt=0
for b in Bs:
 if As[0] < b:
  HP-=b
  cnt+=1
 else:break
 if HP<=0:break
print(cnt+((HP//As[0])+(HP%As[0]!=0)if HP>0 else 0))

Solution (Python):
N,HP=map(int,input().split())
As=[0]*N
Bs=[0]*N
for i in range(N):
    a,b = map(int, input().split())
    As[i] = a
    Bs[i] = b
As.sort(reverse=True)
Bs.sort(reverse=True)

cnt = 0
for b in Bs:
    if As[0] < b:
        HP -= b
        cnt += 1
    else: break
    if HP <= 0: break
print(cnt + ((HP // As[0]) + (HP % As[0] != 0) if HP > 0 else 0))

Solution (Python):
N,HP=map(int,input().split())

As = [0]*N
Bs = [0]*N
for i in range(N):
    a,b = map(int, input().split())
    As[i] = a
    Bs[i] = b
As.sort(reverse=True)
Bs.sort(reverse=True)

cnt = 0
for b in Bs:
    if As[0] < b:
        HP -= b
        cnt += 1
    else:
        break
    if HP <= 0:
        break

if HP > 0:
    print(cnt + (HP // As[0]) + (HP % As[0] != 0))
else:
    print(cnt)

Solution (Python):
n,h=map(int, input().split())
ab=[list(map(int, input().split())) for i in range(n)]
ab.sort(key=lambda x:(-x[0],x[1]))
a=ab.pop(0)
am=a[0]
a1=a[1]
ab.sort(key=lambda x:x[1])
ans=0
while(h>a1):
    if(len(ab)==0):
        h-=a[1]
        ans+=1
        if(h>0):
            ans+=-(-h//am)
            h=0
        break
    t=ab.pop(-1)
    if(am>t[1]):
        h-=a[1]
        ans+=1
        if(h>0):
            ans+=-(-h//am)
            h=0
        break
    h-=t[1]
    ans+=1
if(h>0):
    ans+=1
print(ans)

Solution (Python):
n,m=map(int,input().split())
l1=[]
l2=[]
for i in range(n):
  a,s=map(int,input().split())
  l1.append(a)
  l2.append(s)
m1=max(l1)
c=0
l2=sorted(l2)
for i in range(1,1+len(l2)):
  if m<=0:
    break
  elif l2[-i]>=m1:
    c+=1
    m-=l2[-i]
  else:
    break
if m<=0:
  print(c)
else:
  if m%m1==0:
    c+=m//m1
  else:
    c+=m//m1+1
  print(c)

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

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

ans = 0
while (H > 0):
    if ans < len(b) and b[ans] > maxOfa:
        H -= b[ans]
        ans += 1
    else:
        ans +=(H + maxOfa - 1) // maxOfa
        H = 0

print(ans)

Solution (Python):
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n, h = f()
    swords = []

    for i in range(n):
        swords.append(f())
    
    maxa = max([x[0] for x in swords])

    swords = sorted(swords, key = lambda x: -x[1])

    cnt = 0
    sumh = 0
    for i in range(n):
        if swords[i][1]>maxa:
            sumh += swords[i][1]
            cnt += 1
            if sumh >= h:
                print(cnt)
                return
        else:
            break

    cnt += (h- sumh+maxa-1)//maxa

    print(cnt)






solve()

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

count = 0

max_atack = -1
for i in range(N):
    max_atack = max(max_atack, weapon[i][0]) 


flag = True
weapon = sorted(weapon, key=lambda x: x[1], reverse=True)
for i in range(N):
    if weapon[i][1] >= max_atack:
        count += 1
        H -= weapon[i][1]
        
        if H <= 0:
            flag = False
            break

if flag:
    if H % max_atack == 0:
        count += H // max_atack
    else:
        count += H // max_atack + 1


print(count)

Solution (Python):
from math import ceil
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)
A.sort()
B.sort()
ans=0
for i in B[::-1]:
    if i<A[-1]:
        break
    H-=i
    ans+=1
    if H<=0:
        print(ans)
        quit()
ans+=ceil(H/A[-1])
print(ans)

Solution (Python):
import math
N,H=map(int,input().split())
ab=[[int(x) for x in input().split()] for _ in range(N)]
a,_=max(ab)
B=sorted([b for _,b in ab if b > a], reverse=True)
sb=sum(B)
if sb < H:
	print(len(B)+math.ceil((H-sb)/a))
else:
	B.insert(0, 0)
	for i in range(1, len(B)):
		B[i] += B[i-1]
		if B[i] >= H:
			break
	print(i)

Solution (Python):

import sys
import math

def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    to_swing = max(a)
    to_throw = [s for s in sorted(b, reverse=True) if s > to_swing]
    count = 0
    for s in to_throw:
        H -= s
        count += 1
        if H <= 0:
            print(count) 
            break
    else:
        count += math.ceil(H / to_swing)
        print(int(count))
    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    H = int(next(tokens))  
    a = [int()] * (N)  
    b = [int()] * (N)  
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)

if __name__ == '__main__':
    main()

Solution (Python):
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in [0]*N]

a = max([a for a,b in ab])
b = sorted([b for _,b in ab if b>a])[::-1]
s = sum(b)
if s >= H:
    while s>=H:
        s -= b.pop()
    ans = len(b)+1
else:
    ans = (H-s-1)//a+1+len(b)
print(ans)

Solution (Python):
import math

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

max = max(A)
B.sort(reverse=True)

cnt,i=0,0
while H > 0:
    if i != len(B):
        if B[i] >= max:
            H -= B[i]
            i += 1
        else:
            x = math.ceil(H/max)
            H=-1
            cnt += x-1
    else:
        x = math.ceil(H/max)
        H=-1
        cnt += x-1
    cnt+=1
print(cnt)

Solution (Python):
n,h=map(int,input().split())
ab=[]
for i in range(n):
    ab.append([int(j) for j in input().split()])

from operator import itemgetter
ab.sort(key=itemgetter(0))
nm=ab[-1][0] 

ab.sort(key=itemgetter(1)) 
ab.reverse()

ans=0
for i in range(n):
    if ab[i][1]>=nm:
        h-=ab[i][1]
        ans+=1
    if h<=0:
        print(ans)
        import sys
        sys.exit()
import math
ans+=math.ceil(h/nm)
print(ans)

Solution (Python):
N,H=map(int,input().split())
a=list()
b=list()
maxs=0
for j in range(N):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
maxa=max(a)
a.sort()
b.sort()
ans=0
while len(b)>0:
    if(H<=0):
        break
    
    if(b[-1]>=maxa):
        H-=b[-1]
        b.pop()
        ans+=1
    else:
        break
if(H>0):
    ans+=H//maxa
    if(H%maxa>0):
        ans+=1
print(ans)

Solution (Python):
n,h=map(int,input().split())
a,b=[],[]
for i in range(n):
    j,k=map(int,input().split())
    a.append(j)
    b.append(k)
am=max(a)
bm=[]
for i in b:
    if am<i:bm.append(i)
if sum(bm)<h:print(len(bm)+(h-sum(bm)+am-1)//am)
else:
    bm.sort()
    ans=0
    while h>0:
        h-=bm.pop(-1)
        ans+=1
    print(ans)

Solution (Python):
n, h = map(int, input().split())
ab = [ [ int(x) for x in input().split() ] for _ in range(n) ]

ab.sort(key=lambda x: x[1], reverse=True)
max_attack = max(ab)[0]

ans = 0
for _, b in ab:
    if h <= 0:
        break
    if b > max_attack:
        h -= b
        ans += 1
    else:
        break

print( ans+max(0, (h+max_attack-1)//max_attack) )

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
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())

n,h = li()

def extract_gt_maxa(b: list, maxa: int) -> list:
    b.sort(reverse=True)
    ret = []
    for bi in b:
        if bi < maxa:
            break
        
        ret.append(bi)
        
    return ret

alist = []
blist = []
for _ in range(n):
    a,b = li()
    alist.append(a)
    blist.append(b)
    
b_gt_maxa = extract_gt_maxa(blist, max(alist))

ans = 0
for bi in b_gt_maxa:
    if h <= 0:
        break
    
    h -= bi
    ans += 1
    
if h > 0:
    ans += -(-h // max(alist))

print(ans)

Solution (Python):
import math
from operator import itemgetter
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,H = IL()
ab = [IL() for i in range(N)]

ab.sort(reverse=True)
attack = ab[0][0]
skill = ab[0][1]

ab.sort(reverse=True,key=itemgetter(1))
cnt = 0
f = 0
for i in range(N):
	if ab[i][1] > attack:
		H -= ab[i][1]
		cnt += 1
	if H <= 0:
		print(cnt)
		exit()

print(cnt + math.ceil(H/attack))

Solution (Python):
n,h = map(int,input().split())
l = [list(map(int,input().split())) for _ in range(n)]
l = sorted(l,key=lambda x:(-x[0],x[1]))
max = l[0]
l.pop(0)
l = sorted(l,key=lambda x:-x[1])
cnt = 0
for i in range(n-1):
    if max[0]<=l[i][1]:
        h -= l[i][1]
        cnt += 1
    if h<=0:
        print(cnt)
        exit()
    if h-max[1]<=0:
        print(cnt+1)
        exit()
h-=max[1]
cnt+=1
if h<=0:
    print(cnt)
elif h%max[0]==0:
    print(cnt+h//max[0])
else:
    print(cnt+h//max[0]+1)

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)

shake = max(a)
throw = 0
for i in b:
    if i > shake:
        throw += i

b.sort(reverse=True)

ans = 0
if throw < H:
    ans += (H-throw+shake-1)//shake
    H -= ans * shake

i=0
while H>0:
    ans += 1
    H -= b[i]
    i += 1


print(ans)

Solution (Python):

def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import math
n,h=IL()
a=0
B=[0]*n
for i in range(n):
    ta,tb=IL()
    a=max(a,ta)
    B[i]=tb
B.sort()
ans=0
for i in range(n):
    if B[-1-i]>=a and h>0:
        h-=B[-1-i]
        ans+=1
    else:
        break
if h>0:
    ans+=math.ceil(h/a)
print(ans)