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):
import bisect
n,h = map(int, input().split( ))
a = []
b = []
for i in range(n):
    ai,bi = map(int, input().split( ))
    a.append(ai)
    b.append(bi)


a_max = max(a)
b.sort()
j = bisect.bisect_left(b,a_max)

b_sum = sum(b[j:])

ans = n-j
h -= b_sum

if h>=0:
    ans += h//a_max

    if h%a_max:
        ans += 1

    print(ans)
else:
    while h<0:
        h+=b[j]
        j+=1
        ans -=1
    if h>0:
        ans +=1
    print(ans)

Solution (Python):
import sys
from math import ceil
input = sys.stdin.readline
N, H = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
maxA = max(A)
B = sorted([n for n in B if n > maxA], reverse=True)
ans = 0
for b in B:
    H -= b
    ans += 1
    if H < 1:
        break
else:
    print(ans+ceil(H/maxA))
    exit()
print(ans)

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, h = LI()
A = []
B = []
for _ in range(n):
    a, b = LI()
    A += [a]
    B += [b]

max_a = max(A)
power_sort = sorted(B + [max_a], reverse=True)
for i in range(n + 1):
    h -= power_sort[i]
    if h <= 0:
        print(i + 1)
        exit()
    elif power_sort[i] == max_a:
         print(h // max_a + bool(h % max_a) + i + 1)
         exit()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
from pprint import pprint
from copy import deepcopy
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce
from pprint import pprint


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007

n, h = LI()
power = []
for a, b in LIR(n):
    power += [(a, 1)]
    power += [(b, 0)]


power.sort(reverse=True)
for i in range(2 * n):
    p, flag = power[i]
    h -= p
    if h <= 0:
        print(i + 1)
        exit()
    elif flag:
        print(i + h // p + bool(h % p) + 1)
        exit()

Solution (Python):
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
B.sort()
C = iter(B[B > m][::-1])

count = 0

try:
    while H > 0:
        H -= next(C)
        count += 1
except StopIteration:
    Q, R = divmod(H, m)
    print(count + Q + bool(R))
else:
    print(count)

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

s=[]
for i in range(N):
    
    
    s.append(tuple(map(int,input().split())))

s.sort(reverse=True)
a=s[0][0]
b=sorted([t[1] for t in s if t[1]>a],reverse=True)
'''
print(s)
print(a)
print(b)
'''
ans=0
for bi in b:
    H-=bi
    ans+=1
    if H<=0:
        break

if H>0:
    ans+=(H+a-1)//a

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

import heapq

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

pq = []
amax = 0

for i in range(n):
    a,b = map(int, input().split())
    heapq.heappush(pq, -b)
    if a > amax:
        amax = a

heapq.heappush(pq, -amax)

d = 0
dtotal = 0
ans = 0

while dtotal > -h:
    d = heapq.heappop(pq)
    dtotal += d
    ans += 1
    if d == -amax:
        break
if -dtotal < h:
    if (h+dtotal)%amax == 0:
        ans += (h+dtotal)//amax
    else:
        ans += 1 + (h+dtotal)//amax

print(ans)

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

Data2 = list(filter(lambda x:x[1]>=maxPower,Data))
Data2.sort(key=lambda x:x[1],reverse=True)

ans = 0
left = H
for d in Data2:
    left -= d[1]
    ans += 1
    if left <= 0:
        break

if left > 0:
    ans += (left//maxPower)
    if left % maxPower > 0:
        ans += 1

print(ans)

Solution (Python):
from sys import stdin
import bisect
import math

n,m = [int(x) for x in stdin.readline().rstrip().split()]
a,b = [],[]
for i in range(n):
    x,y = [int(x) for x in stdin.readline().rstrip().split()]
    a.append(x)
    b.append(y)
a.sort()
b.sort()
max_a = a[-1]
li = b[bisect.bisect_left(b,max_a):]

damage = 0
point = 0

while True:
    if li:
        damage += li.pop()
        point += 1
    else:
        break
    if damage >= m:
        print(point)
        exit()

point += math.ceil((m-damage)/max_a)
print(point)

Solution (Python):
n, h = map(int, input().split())
slash = 0
throw = []

for i in range(n):
    a, b = map(int, input().split())
    slash = max(slash, a)
    throw.append(b)

throw.sort(reverse=True)
count = 0

for damage in throw:
    if h <= 0:
        print(count)
        exit()
    if damage <= slash:
        break
    h -= damage
    count += 1

count += h//slash
count += bool(h % slash)
print(count)

Solution (Python):
import math
n, h = map(int, input().split())
a = []
b = []
ans = 0
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.sort(reverse=True)
b.sort(reverse=True)
max_a = a[0]
for i in range(n):
    if b[i] >= max_a:
        h -= b[i]
        ans += 1
    else:
        break
    if h <= 0:
        break
if h > 0:
    ans += math.ceil(h / max_a)
print(ans)

Solution (Python):
import math

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

m=max(a)
j=n
for i in range(n):
    if b[i]<m:
        j=i
        break
x=0
for i in range(j):
    x+=b[i]
    if x>=h:
        print(i+1)
        break
else:
    print(j+math.ceil((h-x)/m))

Solution (Python):
N, H = map(int, input().split())
A = [0] * N
B = [0] * N
count = 0
for i in range(N):
    A[i], B[i] = map(int, input().split())
A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
maximum_Val = A[0]
for i in B:
    if maximum_Val > i:
        break
    H -= i
    count += 1
    if H <= 0:
        print(count)
        exit(0)
if H % maximum_Val == 0:
    print(count + int(H / maximum_Val))
else:
    print(count + int(H / maximum_Val) + 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())
h_rest = h
b.sort()
max_a = max(a)
ans = 0
for j in range(n):
    if b[n-j-1] > max_a:
        ans+=1
        h_rest = h_rest - b[n-j-1]
        if h_rest <= 0:
            break
    else:
        break
if h_rest>0:
    ans+= h_rest//max_a
    if h_rest%max_a>0:
        ans+=1
print(ans)

Solution (Python):
n, h = map(int, input().split())
A, B = [], []
for _ in range(n):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)

B = sorted(B, reverse=True)
a_max = max(A)

bigger = [x for x in B if x >= a_max]
throw_b = len(bigger)

throw = 0
check = 0

while check == 0:
    if throw >= throw_b:
        break
    h = h - B[throw]
    throw += 1
    if h <= 0:
        break

if h <= 0:
    ans = throw
else:
    ans = throw + -(-h//max(A))

print(ans)

Solution (Python):
import sys
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())

B.sort()
B.reverse()
a=max(A)
c=0
p=0
for i in range(N):
    if B[i]<a:
        if (H-p) % a == 0:
            print((H-p)//a+c)
        else:
            print((H-p)//a+c+1)
        sys.exit()
    p+=B[i]
    c+=1
    if p>=H:
        print(c)
        sys.exit()
else:
    if (H-p) % a == 0:
        print((H-p)//a+c)
    else:
        print((H-p)//a+c+1)

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

for i in range(N):
    L[i][0],L[i][1]=map(int,input().split())
L=sorted(L,key=lambda x: (x[0]))

d=L[N-1][0]
L2=sorted(L,key=lambda x: (x[1]))

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

if(H>0):
    if(H%d!=0):
        c+=1
    c+=(H//d)


print(c)

Solution (Python):
import bisect
from math import ceil

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

a_max = max(a)

ans = 0
b.sort()
a.sort()
damage = 0
while damage < H:
  if len(b) >= 1 and b[-1] > a_max:
    damage += b.pop()
    ans += 1
  else:
    ans += ceil((H-damage)/a[-1])
    damage = H
print(ans)

Solution (Python):
n,h = map(int,input().split())
ab = [list(map(int,input().split())) for i in range(n)]
ans = 0
attck = max(ab)[0]
ULT = []
for a,b in ab:
    if b > attck:
        ULT.append(b)

ULT.sort(reverse=1)

for ult in ULT:
    h -= ult
    ans += 1
    if h <= 0:
        h = 0
        break

ans += h//attck+1 if h%attck else h//attck
print(ans)

Solution (Python):
dbflag=""

def debug(*args):
	if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
	if ""!=dbflag:return _INDATA.readline()
	else: return input()


result = 0


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




import numpy as np
data=np.ndarray(shape=(N,2),dtype=int)


for i in range(0,N):
	data[i,:]=[int(x) for x in readline().split(' ')]

maxi=np.argmax(data[:,0])
amax=data[maxi,0]

B=data[:,1]
BoverA = sorted((B[B > amax])[:],reverse=True)
lenBoverA=len(BoverA)

curH =H
for i in range(0,lenBoverA):
	curH-=BoverA[i]
	result +=1
	if curH<=0: break


import math

if curH >0:
	result+=math.ceil(curH / amax)

print(result)

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]
A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
C=A[0]
count=0
for i in range(N):
  if B[i]>=C:
    H -=B[i]
    count +=1
    if H<=0:
      print(count)
      exit()
answer=count-(-H//C)
print(answer)

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]
A=sorted(A,reverse=True)
B=sorted(B,reverse=True)
C=A[0]
count=0
for i in range(N):
  if B[i]>=C:
    H -=B[i]
    count +=1
    if H<=0:
      print(count)
      exit()
answer=count-(-H//C)
print(answer)

Solution (Python):
import heapq as hq
from math import ceil
N, H = map(int, input().split())
A = 0
B = []
for i in range(N):
  a, b = map(int, input().split())
  A = max(A, a)
  hq.heappush(B, -b)

ans = 0
while H > 0 and B:
  b = -hq.heappop(B)
  if b > A:
    H -= b
    ans += 1
  else:
    break

if H > 0:
  ans += ceil(H / A)

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline

def main():
    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())

    cnt = 0
    max_A = max(A)
    sort_B = sorted(B, reverse=True)
    for b in sort_B:
        if b > max_A:
            cnt += 1
            H -= b
        else:
            break

        if H <= 0:
            break
    
    if H > 0:
        cnt += H // max_A if H % max_A == 0 else H // max_A + 1
    print(cnt)



if __name__ == "__main__":
    main()

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

a_list = []
b_list = []
for i in range(N):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    
max_a = max(a_list)
new_b_list = []
for i in range(len(b_list)):
    if max_a <= b_list[i]:
        new_b_list.append(b_list[i])
    
count = 0
new_b_list = sorted(new_b_list, reverse=True)
for i in range(len(new_b_list)):
    H -= new_b_list[i]
    count += 1
    if H <= 0:
        print(count)
        exit()


count += (H-1) // max_a + 1

print(count)

Solution (Python):
import sys

import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline


def main():
    N, H = map(int, readline().split())
    m = map(int, read().split())
    AB = np.array(list(zip(m, m)))

    A_max = np.max(AB[:, 0])
    B = AB[:, 1]
    B = np.sort(B)[::-1]
    B = B[B > A_max]
    cnt = 0
    d = 0
    for b in B:
        d += b
        cnt += 1
        if H <= d:
            print(cnt)
            sys.exit()

    ans = (H - d) / A_max + cnt
    if ans % 1 != 0:
        ans = int(ans) + 1

    print(int(ans))


main()

Solution (Python):
import sys
import math
n, h = [int(i) for i in sys.stdin.readline().split()]
a_ls = []
b_ls = []
for i in range(n):
    a, b = [int(i) for i in sys.stdin.readline().split()]
    a_ls.append(a)
    b_ls.append(b)
a_ls.sort()
b_ls.sort()
cnt = 0
_sum = 0
for b in b_ls[::-1]:
    if b < a_ls[-1]:
        break
    _sum += b
    cnt += 1
    if _sum >= h:
        break
cnt += math.ceil(max(0, h - _sum) / a_ls[-1])
print(cnt)

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 = int(max(a))
B = [i for i in b if i > A]

B.sort(reverse=True)

Sum = 0

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

if H > 0:
    Sum += int((H-1)//A)+1


print(Sum)

Solution (Python):
import sys
import math
from collections import defaultdict
input = sys.stdin.readline
N, H = [int(x) for x in input().strip().split()]
A = [0] * N
B = [0] * N
a_max = 0

for n in range(N):
    a, b = [int(x) for x in input().strip().split()]
    a_max = max(a_max, a)
    A[n] = a
    B[n] = b

B = sorted([b for b in B if b >= a_max], reverse=True)
ans = 0
damage = 0
if sum(B) >= H:
    while damage < H:
        ans += 1
        damage += B[ans-1]
    print(ans)
else:
    ans = len(B)
    damage = sum(B)
    ans += math.ceil((H - damage) / a_max)
    print(ans)

Solution (Python):
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
amax=max(A)
for i in range(n):
    if amax<=B[i]:
        C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    if ((h-ans)//amax)*amax<h-ans:
        cnt+=(h-ans)//amax+1
    else:
        cnt+=(h-ans)//amax
        
print(cnt)

Solution (Python):
n,h=map(int,input().split())
A=[]
B=[]
C=[]
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
amax=max(A)
for i in range(n):
    if amax<=B[i]:
        C.append(B[i])
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
cnt=0
ans=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    if ((h-ans)//amax)*amax>=h-ans:
        cnt+=(h-ans)//amax
    else:
        cnt+=(h-ans)//amax+1
        
print(cnt)

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

al = []
bl = []

for _ in range(n):
    a,b = map(int,input().split())
    al.append(a)
    bl.append(b)

amax = max(al)
bl = [i for i in bl if i > amax]

bl = sorted(bl, reverse=True)

ans = 0
for b in bl:
    h -= b
    ans += 1
    if h <= 0:
        print(ans)
        import sys
        sys.exit()

import math
print(ans + math.ceil(h/amax))

Solution (Python):

import sys
import math

def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    ab = list(zip(a,b))

    max_a = 0
    for i in range(N):
        if max_a < a[i]:
            max_a = a[i]

    b_sort = sorted(ab,key=lambda x: -x[1])
    answer = 0
    Hitpoint = H

    for _,bb in b_sort:
        
        if bb <= max_a:
            break

        Hitpoint -= bb
        answer += 1

        if Hitpoint <= 0:
            print(answer)
            return
    answer += math.ceil(Hitpoint/max_a)
    print(answer)
    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):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    md = 0
    dl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        md = max(md, a)
        dl.append(b)
    dl.sort(reverse=True)
    cnt = 0
    for v in dl:
        if v > md:
            h -= min(h, v)
            cnt += 1
            if h == 0:
                print(cnt)
                exit()
        else:
            break
    cnt += (h + md - 1) // md
    print(cnt)
    exit()


if __name__ == '__main__':
    solve()

Solution (Python):
N,H=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(N)]
a=max([i[0] for i in AB])
B=sorted([i[1] for i in AB if i[1]>a],reverse=True)
count=0
for b in B:
    H-=b
    count+=1
    if H<=0:
        break

if H>0:
    count+=H//a + 1* (H%a>0)

print(count)

Solution (Python):
n, h = map(int, input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
x=0
a_list = [e[i][0] for i in range(n)]
t_list = [e[i][1] for i in range(n)]
a=max(a_list)
t_list=sorted((i for i in t_list if i >a),reverse=True)
if h>sum(t_list):
  h=h-sum(t_list)
  x=len(t_list)+(-(-h//a))
else:
  for i in range(len(t_list)):
    h=h-t_list[i]
    x=x+1
    if h<=0:
      break 
print(x)

Solution (Python):
import sys
from math import ceil

input = sys.stdin.readline

def main():
    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(reverse=True)
    B.sort(reverse=True)
    
    a = A[0]
    ans = 0
    
    for b in B:
        if a > b or H <= 0: break
        H -= b
        ans += 1
        
    if H > 0: ans += ceil(H / a)
    
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import math
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

B.sort(reverse=True)
def calc():
    maxa = max(A)
    cnt = 0
    h = H
    for b in B:
        if maxa < b:
            cnt += 1
            h -= b
        if h <= 0:
            return cnt

    
    cnt += math.ceil(h/maxa)
    return cnt

print(int(calc()))

Solution (Python):
n,h=map(int,input().split())
a=[0]*n
b=[0]*n
maxa=0
minb=10**9+1
for i in range(n):
  a[i],b[i]=map(int,input().split())
  maxa=max(maxa,a[i])
for i in range(len(b)):
  if b[i]<maxa:
    b[i]=0
b=sorted(b)[::-1]
ans=0
for i in range(len(b)):
  if b[i]==0:
    break
  h-=b[i]
  ans+=1
  if h<=0:
    print(ans)
    exit(0)
print(ans+h//maxa+(h%maxa!=0))

Solution (Python):
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
from math import ceil
def resolve():
    n,h=map(int,input().split())
    AB=[tuple(map(int,input().split())) for _ in range(n)]

    
    AB.sort(lambda x:(x[0],-x[1]))
    ma,mb=AB.pop()

    
    AB.sort(lambda x:-x[1])
    ans=0
    for i in range(n-1):
        a,b=AB[i]
        if(b<=ma): break
        h-=b
        ans+=1
        if(h<=0):
            print(ans)
            return
    ans+=min(ceil(h/ma),ceil((h-mb)/ma)+1)
    print(ans)
resolve()

Solution (Python):
from math import ceil

n,h= map(int,input().split())
A=[]
B=[]

for _ in range(n):
  a,b = map(int,input().split())
  A.append(a)
  B.append(b)

max_a = max(A)

finish = []
for b in B:
  if b > max_a:
    finish.append(b)    
    
ans = 0
if sum(finish) < h :
  ans += len(finish)
  ans += ceil((h-sum(finish))/max_a)
else:
  damage = 0
  for d in sorted(finish,reverse=True):
    damage += d
    ans += 1
    if damage >= h:
      break

print(ans)

Solution (Python):
import bisect
def main():

    n,h=map(int,input().split())
    a=[]
    b=[]
    for _ in range(n):
        a_,b_=map(int,input().split())
        a.append(a_)
        b.append(b_)
    sumb=sum(b)
    a.sort()
    b.sort()
    cnt=0
    
    low=0
    high=n-1
    mid=0
    temp=h
    
    
    
    
    
    
    
    idx=bisect.bisect_left(b,a[-1])
    mid=idx
    
    if n != 1:
        if mid != n:
            for i in range(n-1,mid-1,-1):
                
                h-=b[i]
                cnt+=1
                if h<= 0:
                    print(cnt)
                    return
    else:
        cnt=1
        h-=b[0]
        if h<=0:
            print(cnt)
            return

    
    cnt+=-(-h//a[-1])
    print(cnt)
    return
    
    
    
    
    
    
    
    
    
    
    
    
    
    

    
    
    
    
    
    
    
    
    
    

if __name__=='__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30

def main():
    n, h = map(int, input().strip().split())
    p = []
    for i in range(n):
        a, b = map(int, input().strip().split())
        p.append((a, 0))
        p.append((b, 1))
    p.sort(reverse=True)
    s = 0
    i = 0
    ans = 0
    while s < h:
        s += p[i][0]
        ans += 1
        if p[i][1] == 1:
            i += 1
        else:
            ans += (h - s + p[i][0]-1) // p[i][0]
            break
    print(ans)
if __name__ == '__main__':
    main()

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

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

a_max = 0
b_list = []
count=0

for _ in range(N):
	a, b = map(int, input().split())
	a_max = max(a,a_max)
	b_list.append(b)

b_list.sort(reverse=True)

for b in b_list:
	if b > a_max:
		H -= b
		count += 1
	else:
		break
	if H <= 0:
		print(count)
		exit()

print((H-1)//a_max + 1 +count)

Solution (Python):
N, H = map(int, input().split(' '))
powers = []
for _ in range(N):
    a, b = map(int, input().split(' '))
    powers.extend([[a, True], [b, False]])

powers.sort(key=lambda x: -x[0])

import math
ans = 0
for power, is_a in powers:
    if H <= 0:
        break
    else:
        if is_a:
            ans += int(math.ceil(H/power))
            break
        else:
            H -= power
            ans += 1
print(ans)

Solution (Python):
n,h = map(int,input().split())
al=[]
bl=[]
for _ in [0]*n:
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()
ans = 0
while h>0:
  if len(bl)>0 and bl[-1]>al[-1]:
    h-=bl[-1]
    ans+=1
    del bl[-1]
  else:
    ans += -(-h//al[-1])
    h=0
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline


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

ans = 0

B.sort(reverse=True)
for b in B:
    if b > A:
        ans += 1
        H -= b
        if H <= 0:
            print(ans)
            sys.exit()
            
print(ans + (H-1)//A + 1)

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

for a,_ in ab:
  lisA.append(a)
m = max(lisA)


for _,b in ab:
  if b > m:
  	lisB.append(b)

s = sum(lisB)
lisB.sort(reverse=True)


cnt = 0

if s>=h:
  while s>=h:
    
    s -= lisB.pop()
  cnt = len(lisB) + 1 
else:
  cnt = len(lisB) + math.ceil((h-s)/m)
  
print(cnt)

Solution (Python):
N, H = map(int, input().split())
max_a = 0
blist = []
counter = 0
killed = False
for _ in range(N):
    a, b = map(int, input().split())
    max_a = max(a, max_a)
    blist.append(b)

for b in sorted(blist, reverse=True):
    if H <= 0:
        killed = True
        break
    if b > max_a:
        counter += 1
        H -= b
if killed:
    print(counter)
elif H % max_a == 0:
    print(counter + H // max_a)
else:
    print(counter + H // max_a + 1)

Solution (Python):
import bisect
import math
N, H = map(int, input().split())
a, b = [], []
for i in range(N):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
ma = max(a)
b.sort()
b = list(reversed(b[bisect.bisect_left(b, ma):]))
ans = 0
for i in range(len(b)):
    ans += 1
    H -= b[i]
    if H <= 0:
        print(ans)
        exit()
print(ans + math.ceil(H / ma))

Solution (Python):
import bisect
import math
N, H = map(int, input().split())
a, b = [], []
for i in range(N):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
ma = max(a)
b.sort()
b = list(reversed(b[bisect.bisect_left(b, ma):]))

ans = 0
for i in range(len(b)):
    ans += 1
    H -= b[i]
    if H <= 0:
        print(ans)
        exit()
print(ans + math.ceil(H / ma))

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    ab = []
    n, h = map(int, input().split())
    for _ in range(n):
        a, b = map(int, input().split())
        ab.append([a, 1])
        ab.append([b, 0])
    ab.sort()
    cnt = 0
    while h > 0:
        attack, type = ab.pop()
        if type:
            cnt += (h + attack - 1) // attack
            break
        else:
            h -= attack
            cnt += 1
    print(cnt)

main()

Solution (Python):
def main():
    n,h = map(int,input().split())
    ab=[]
    a_max=0
    for _ in range(n):
        a,b = map(int,input().split())
        ab.append([a,b])
        if a_max<a:
            a_max=a

    ab.sort(reverse=True,key=lambda x:x[1])
    for i in range(n-1,-1,-1):
        if ab[i][0]==a_max:
            index=i+1
            break
    ans=0
    cnt=0
    index2=0
    while index2!=n and ab[index2][1]>a_max:
        cnt+=ab[index2][1]
        ans+=1
        if cnt>=h:
            print(ans)
            return
        index2+=1
    if (h-cnt)%ab[index-1][0]==0:
        ans+=(h-cnt)//ab[index-1][0]
    else:
        ans+=(h-cnt)//ab[index-1][0]+1
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
import math
N, H = map(int, input().split())
A, B = [], []
a_max = 0




for _ in range(N):
	a, b = map(int, input().split())
	a_max = max(a_max, a)
	B.append(b)
B.sort(reverse = True)
for i in range(N):
	if B[i] <= a_max:
		B = B[0 : i]
		break
		

if sum(B) >= H:
	ctr = 0
	for i in range(len(B)):
		ctr += B[i]
		if ctr >= H: break
	print(i + 1)
	

else:
	rest = H - sum(B)
	print(math.ceil(rest / a_max) + len(B))

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    al = 0
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al = max(al, a)
        bl.append(b)
    bl.sort()
    cnt = 0
    while True:
        if len(bl) != 0:
            b = bl.pop()
            if h <= 0:
                print(cnt)
                exit()
            elif al < b:
                h -= min(h, b)
                cnt += 1
            else:
                cnt += (h + al - 1) // al
                h -= (h + al - 1) // al * al
                print(cnt)
                exit()
        else:
            cnt += (h + al - 1) // al
            h -= (h + al - 1) // al * al
            print(cnt)
            exit()


if __name__ == '__main__':
    solve()

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())
maxa = max(A)
c, d = 0, 0
for i in sorted(B)[::-1]:
  if i > maxa:
    c += i
    d += 1
    if c >= h:
      print(d)
      exit()

ans = d - (c-h)//maxa
print(ans)

Solution (Python):
import math
n, h = map(int, input().split())
list_a = []
list_b = []
for i in range(n):
  a, b = list(map(int, input().split()))
  list_a.append(a)
  list_b.append(b)
max_a = max(list_a)
use_b = [b for b in list_b if b > max_a]
use_b.sort(reverse=True)

count = 0
while h > 0:
  if len(use_b) > 0:
    h -= use_b.pop(0)
    count += 1
  else:
    count += math.ceil(h / max_a)
    break
print(count)

Solution (Python):
import math
n,h = map(int, input().split())
a, b = [], []
for _ in range(n):
    c,d = map(int, input().split())
    a.append(c)
    b.append(d)
mx = max(a)
ups = [x for x in b if mx < x]
if sum(ups) >= h:
    tmp = 0
    cnt = 0
    for up in sorted(ups)[::-1]:
        tmp += up
        cnt += 1
        if tmp >= h:
            print(cnt)
            exit()
h -= sum(ups)
ans = len(ups) + math.ceil(h / mx)
print(ans)