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 sys import stdin
N, H = [int(_) for _ in stdin.readline().rstrip().split()]
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = [int(_) for _ in stdin.readline().rstrip().split()]
A.sort()
B.sort(reverse=True)
ans = 0
for b in B:
    if b <= A[-1] or H <= 0:
        break
    H -= b
    ans += 1
print(ans + max(0, (H-1)//A[-1]+1))

Solution (Python):

def main():
    N, H, *AB = map(int, open(0).read().split())
    A = AB[::2]
    x = max(A)
    B = sorted([i for i in AB[1::2] if i > x], reverse=1)
    ans = 0
    for i in B:
        ans += 1
        H -= i
        if H <= 0:
            break
    else:
        ans += (H + x - 1) // x
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N, H = tuple(map(int, input().split()))
    AB = tuple(tuple(map(int, input().split())) for _ in range(N))
    A, B = zip(*AB)
    x = max(A)
    B = sorted([i for i in B if i > x], reverse=1)
    ans = 0
    for i in B:
        ans += 1
        H -= i
        if H <= 0:
            break
    else:
        ans += (H + x - 1) // x
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys
input = sys.stdin.readline

def main():
    N, H = tuple(map(int, input().split()))
    AB = tuple(tuple(map(int, input().split())) for _ in range(N))
    A, B = zip(*AB)
    C = sorted([(i, 0) for i in A] + [(i, 1) for i in B], reverse=1)
    ans = 0
    for i, t in C:
        if t == 0:
            ans += (H + i - 1) // i
            break
        else:
            ans += 1
            H -= i
            if H <= 0:
                break
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N, H = map(int, input().split())
ABs = []
for i in range(N):
  a, b = map(int, input().split())
  ABs.append((a, b))
A = max(map(lambda AB: AB[0], ABs))
Bs = sorted(filter(lambda b: b>A, map(lambda AB: AB[1], ABs)), reverse=True)

r = 0
c = 0
for b in Bs:
  r += 1
  c += b
  if c >= H:
    print(r)
    exit()
r += (H-c +A-1)//A
print(r)

Solution (Python):
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)
  
b_list = sorted(b_list)

count = 0
a_max = max(a_list)

while H > 0 and b_list:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)

Solution (Python):
N, H = map(int, input().split())
nage = []
a_max = 0
for i in range(N):
	a, b = map(int, input().split())
	a_max = max(a_max, a)
	nage.append(b)
nage.sort(reverse=True)
cnt = 0
for i in (i for i in nage if i > a_max):
	cnt += 1
	H -= i
	if H <= 0:
		print(cnt)
		exit()
cnt += -(-H//a_max)
print(cnt)

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)

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

maxa = max(A)

res = 0

for b in B:
    if b < maxa or H <= 0:
        break
    H -= b
    res += 1

res += int((H + maxa - 1) / maxa) if H > 0 else 0

print(res)

Solution (Python):
n,h=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in [0]*n],key=lambda x:[-x[1],-x[0]])
m=0
k=0
for i in range(n):
    if l[i][0]>=m:
        m=l[i][0]
        k=i
hp=0
c=0
for i in range(n):
    if l[i][1]<l[k][0]:break
    if i==k:continue
    hp+=l[i][1]
    c+=1
    if hp>=h:print(c);exit()
print((h-hp-l[k][1]+l[k][0]-1)//l[k][0]+c+1)

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)

cnt = 0
Bs = [0] + sorted(Bs)
b = Bs.pop()
a = max(As)
while H > 0 and b > a:
    
    H -= b 
    cnt += 1
    b = Bs.pop()
cnt += max(0,int(math.ceil(H / a)))

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.sort(reverse=True)
B.sort(reverse=True)

c = 0
for j in range(n):
  if B[j] >= A[0]:
    c += 1
    h -= B[j]
    if h <= 0:
      print(c)
      exit()
  else:
    break
if h%A[0] == 0:
  c += h//A[0]
else:
  c += h//A[0]+1
print(c)

Solution (Python):



import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))


n,h = LI()
maxa = 0
ab = []
for _ in range(n):
    a,b = LI()
    maxa = max(maxa,a)
    ab.append([a,b])
x = sorted(ab,key = lambda x:x[1],reverse = True)
cnt = 0
for i in range(n):
    a,b = x[i]
    if maxa <= b:
        h -= b
        cnt += 1
    if h <= 0:
        print(cnt)
        quit()
cnt += math.ceil(h / maxa)
print(cnt)

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

def ceil(s, t):
    if s%t == 0:
        return s//t
    else:
        return s//t + 1


x = max(a)
b_list= []
for i in range(N):
    if b[i] > x :
        b_list.append(b[i])

y = sum(b_list)

b_list.sort(reverse=True)

ans = 0

for i in b_list:
    H -= i
    ans += 1
    if H > 0:
        pass
    elif H  == 0:
        break
    elif H < 0:
        break

if H > 0:
    ans += ceil(H, x)

print(ans)

Solution (Python):
N, H = map(int, input().split())
bs = []
maxA = 0
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    maxA = max(maxA, a)
    bs.append(b)
bs.sort(reverse=True)

for b in bs:
    if H <= 0: break
    if b > maxA:
        H -= b
        ans += 1

if H > 0:
    ans += (-(-H//maxA))
print(ans)

Solution (Python):
import heapq

N, H = map(int, input().split())
b = []
max_a = 0
for i in range(N):
    ai, bi = map(int, input().split())
    heapq.heappush(b, -bi)
    max_a = max(ai, max_a)

ans = 0
while b != [] and H > 0:
    bi = -heapq.heappop(b)
    if bi < max_a:
        break
    H -= bi
    ans += 1
if H > 0:
    ans += (H + max_a - 1) // max_a
print(ans)

Solution (Python):




n, h = map(int, input().split())
a, b = 0, []
for _ in range(n):
    ai, bi = map(int, input().split())
    a = max(a, ai)
    b.append(bi)
b = list(sorted(b))

l, r = 0, n
while r-l > 0:
    mid = (l + r) // 2
    if b[mid] >= a:
        r = mid
    else:
        l = mid + 1
b = b[r:][::-1]
count = 0
for bi in b:
    h -= bi
    count += 1
    if h <= 0:
        break

if h > 0:
    count += h // a if h % a == 0 else h // a + 1

print(count)

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

N,H = map(int,input().split())
ab_array = [list(map(int,input().split())) for _ in range(N)]
ab_array = sorted(ab_array,key=lambda x: -x[1])
a_array = [ab[0] for ab in ab_array]
a_array.sort()
a_max = a_array[-1]


h = 0
ans = 0
for ab in ab_array:
    print
    a,b = ab
    if b <= a_max:
        break
    h += b
    ans += 1
    if h >= H:
        print(ans)
        exit()
ans += math.ceil((H-h)/a_max)
print(ans)

Solution (Python):
import math
n,h=map(int,input().split())
l=sorted([list(map(int,input().split())) for _ in range(n)],reverse=True)
lt=sorted([i[1] for i in l[1:] if i[1]>l[0][0]])
a,b=l[0]
ans=0
if a>b:
    while h>0:
        if lt:h-=lt.pop()
        else:h-=a
        ans+=1
    print(ans)
else:
    while h>b and lt:
        h-=lt.pop()
        ans+=1
    ans+=max(math.ceil((h-b)/a),0)
    h-=max(math.ceil((h-b)/a)*a,0)
    if h>0:
        ans+=1
    print(ans)

Solution (Python):
N, H = map(int, input().split())
AB = []
for _ in range(N):
    a, b = map(int, input().split())
    AB.append((a, True))
    AB.append((b, False))
AB.sort(reverse=True)
n = 0
for h, isinf in AB:
    if not isinf:
        n += 1
        H -= h
    else:
        n += (H - 1) // h + 1
        H = 0
    if H <= 0:
        print(n)
        exit()

Solution (Python):
ip = input()
ip = ip.split(" ")
n = int(ip[0])
h = int(ip[1])

dmg = []

for i in range(n):
  ip = input()
  ip = ip.split(" ")
  dmg.append([int(ip[0]), 0])
  dmg.append([int(ip[1]), 1])

dmg_sorted = sorted(dmg, reverse=True)

rs = 0
i = 0
j = 0
while i <= len(dmg_sorted):
  if dmg_sorted[i][1] == 1:
    h = h - dmg_sorted[i][0]
    rs = rs + 1
    i = i + 1
    j = j + 1
  elif dmg_sorted[i][1] == 0:
    rs = rs + h // dmg_sorted[i][0]
    if(h % dmg_sorted[i][0] != 0):
      rs = rs + 1
    else:
      pass
    j = j + 1
    break
  else:
    raise ValueError("hoge")
  
  if h <= 0:
    break
  else:
    pass
  
print(rs)

Solution (Python):
n, h = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
A, B = zip(*l)
max_a = max(A)
c = 0
for b in sorted([b for b in B if b > max_a], reverse=True):
  h -= b
  c += 1
  if h <= 0:
    print(c)
    exit()
print(c + h // max_a + (h % max_a != 0))

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

max_a = max(l, key=lambda x: x[0])[0]
l = [[a, b] for a, b in l if b > max_a]
l.sort(key=lambda x: x[1], reverse=True)

c = 0
for a, b in l:
  h -= b
  c += 1
  if h <= 0:
    print(c)
    exit()

print(c + h // max_a + (h % max_a != 0))

Solution (Python):
if __name__ == '__main__':
    N, H = map(int, input().split())
    A = [None]*N
    B = [None]*N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    
    A_max = max(A)
    B.sort(reverse=True)
    throw_max = 0
    while B[throw_max] >= A_max:
        throw_max += 1
        if throw_max == N:
            break


    count = 0
    Damage = 0
    for i in range(throw_max):
        Damage += B[i]
        count += 1
        if Damage >= H:
            break
    if Damage < H:
        count += int((H - Damage)/A_max)
        if (H - Damage)%A_max != 0:
            count += 1
    print(count)

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

dagger.sort(reverse= True)

count = 0
while H > 0:
    if count < N and dagger[count] > swing:
        H -= dagger[count]
        count += 1
    else:
        count += math.ceil(H/swing)
        break
print(count)

Solution (Python):
n, h = list(map(int, input().split(' ')))
k = [list(map(int, input().split(' '))) for _ in range(n)]
a = []
b = []
for i in range(n):
    a.append(k[i][0])
    b.append(k[i][1])

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h > 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        count += h//a[x]
        if h%a[x] != 0:
            count += 1
        h = 0
print(count)

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

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

i = 0
count = 0
while M > 0:
	if i < N and X[i][1] > a:
		M -= X[i][1]
		i += 1
	else:
		count += -(-M//a)
		break
	count += 1

print(count)

Solution (Python):
n,h,*l=map(int,open(0).read().split())
a=max(l[::2])
c=0;f=1
for b in sorted(l[1::2])[::-1]:
	if b>a:
		h-=b
		c+=1
		if h<1:
			f=0
			break
print(c+(~-h//a+1)*f)

Solution (Python):
from collections import deque
n,h=map(int,input().split())
l=[list(map(int,input().split())) for _ in range(n)]
l.sort(reverse=True)
fa,fb=l[0]
M=max(fa,fb)
if n==1:
	print(max(0,(h-M-1)//fa)+2-(h<=M))
else:
	cnt=0;tmp=[]
	for _,j in l[1:]:
		if j>fa:
			tmp.append(j)
	b=deque(sorted(tmp))
	lim=len(b)
	while h > M and cnt < lim:
		h-=b.pop()
		cnt+=1
	if len(b)!=0:
		print(cnt+1)
	else:
		print(cnt+max(0,(h-M-1)//fa)+2-(h<=M))

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

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


idx = 0
count = 0
while h > 0:
    if idx < n and b[idx] > a_max:
        h -= b[idx]
        idx += 1
    else:
        count += math.ceil(h / a_max)
        break
    count += 1
print(count)

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

    max_atks_swing = 0
    atks_throw = []
    for i in range(N):
        s, t = map(lambda x: int(x), input().split(' '))
        if max_atks_swing < s:
            max_atks_swing = s
        atks_throw.append(t)
    
    filtered_atks_throw = sorted(
                            filter(lambda x: max_atks_swing < x, atks_throw)
                            ,reverse=True
                          )

    n = 0
    remain = H
    for atk in filtered_atks_throw:
        n += 1
        remain -= atk
        
        if remain <= 0:
            return n

    q, mod = divmod(remain,max_atks_swing)

    return n + q + (1 if mod > 0 else 0)


print(main())

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)
B = sorted(B, reverse=True)
max_a = max(A)
i = 0 
while (i < N and B[i] > max_a):
  H -= B[i]
  if H <= 0:
    print(i+1)
    exit(0)
  i += 1
print(i + (H + max_a-1)//max_a)

Solution (Python):
import sys

input = sys.stdin.readline

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

slash_throw = [[int(x) for x in input().split()] for _ in range(N)]

slashs = []
throws = []

for slash, throw in slash_throw:
    slashs.append(slash)
    throws.append(throw)

max_slash = sorted(slashs)[-1]
throws.sort(reverse=True)
remaining_hp = H
attack_count = 0

for throw in throws:
    if throw > max_slash:
        remaining_hp -= throw
        attack_count += 1
        if remaining_hp <= 0:
            break

if remaining_hp > 0:
    attack_count += -(remaining_hp // -max_slash)

print(attack_count)

Solution (Python):



import queue

def ri():
    return int(input())

def rl():
    return list(input().split())

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

def main():
    n, h = rli()
    la = []
    lb = []
    for _ in range(n):
        a, b = rli()
        la.append(a)
        lb.append(b)
    a = max(la)
    lb = sorted([b for b in lb if b > a], reverse=True)
    ans = 0
    for b in lb:
        h -= b
        ans += 1
        if h <= 0:
            break
    if h > 0:
        ans += (h+a-1) // a
    print(ans)




if __name__ == '__main__':
    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)
  
B.sort(reverse=True)
max_a = max(A)
count = 0
for b in B:
    if max_a <= b:
        H -= b
        count += 1
        if H <= 0:
            break
    else:
        break
if H > 0:
    count += math.ceil(H / max_a)
print(count)

Solution (Python):
N, H = map(int, input().split())
damages = []
for _ in range(N):
  slash, throw = map(int, input().split())
  damages.append((0, slash))
  damages.append((1, throw))
damages.sort(key=lambda x: -x[1])
cnt = 0
damage = 0
idx = 0
while True:
  if damage >= H:
    print(cnt)
    break
  else:
    if damages[idx][0] == 1:
      damage += damages[idx][1]
    else:
      rest = H-damage
      if rest%damages[idx][1] == 0:
        cnt += rest//damages[idx][1]
      else:
        cnt += rest//damages[idx][1]+1
      print(cnt)
      break
    cnt += 1
    idx += 1

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
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque

from itertools import product

from itertools import permutations

from itertools import combinations

from itertools import accumulate
from bisect import bisect_left, bisect_right

import re



def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 


def create_grid(W, H, value = 0):
    return [[ value for _ in range(H)] for _ in range(W)]


N, H = l_inpl()
a, b = [], []

for _ in range(N):
    ai, bi = l_inpl()
    a.append(ai)
    b.append(bi)

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

ans = 0
for bi in b[bisect_right(b, max_a):][::-1]:
    H -= bi
    ans += 1
    if H <= 0:
        break

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

print(ans)

Solution (Python):
n,h,*t=map(int,open(0).read().split())
b=sorted(t[1::2])
a=max(t[::2])
c=0
while h>0and b and b[-1]>a:
    h-=b.pop()
    c+=1
if h>0:c-=-h//a
print(c)

Solution (Python):
n,h,*t=map(int,open(0).read().split())
b=sorted(t[1::2])
a=max(t[::2])
c=0
while h>0and b and b[-1]>a:
    h-=b.pop()
    c+=1
if h>0:c-=-h//a
print(c)

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)
B.sort(reverse=True)
a = max(A)
ans = 0
for b in B:
    if a<b:
        H-=b
    else:
        H-=a
    ans+=1
    if H<=0:break
print(ans if H<=0 else ans+H//a if H%a==0 else ans+H//a+1)

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)

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

c = 0
for b in B:
    if b < A[0] or H <= 0:
        break
    H -= b
    c += 1

if H > 0:
    c += H // A[0]
    if H % A[0] != 0:
        c += 1

print(c)

Solution (Python):
import math
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 = sorted(B, reverse=True)
maxa = max(A)
ans = 0
for b in B:
    if b < maxa:
        break
    ans += 1
    H -= b
    if H <= 0:
        break
H = max(0, H)
ans += math.ceil(H/maxa)
print(ans)

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

def main():
    N, H = map(int, input().split())
    b = [0] * N
    a_max = 0
    for i in range(N):
        t1, t2 = map(int, input().split())
        a_max = max(a_max, t1)
        b[i] = t2

    b = sorted(b, reverse=True) 

    count = 0
    for i in range(N):
        if H > 0 and b[i] > a_max: 
            H -= b[i]
            count += 1
        else:
            break
    if H > 0:
        count += math.ceil(H/a_max) 
    print(count)

if __name__ == "__main__":
    main()

Solution (Python):
def MI():
    return map(int,input().split())
def I():
    return int(input())
def LI():
    return [int(i) for i in input().split()]

n,h=MI()
a=[]
b=[]
for i in range(n):
    x,y=MI()
    a.append(x)
    b.append(y)
a.sort()
b.sort()
A=a[-1]
for i in range(n):
    if b[i]>=A:
        c=[A]+b[i:]
        break
c=c[::-1]
ans=0
for i in range(len(c)-1):
    ans+=1
    h-=c[i]
    if h<=0:
        break
if h>0:
    ans+=(h+A-1)//A
print(ans)

Solution (Python):
from math import ceil


def f(n, h, A, B):
    cnt = 0

    a = max(A)
    for b in sorted(B, reverse=True):
        if b <= a:
            break
        if h <= 0:
            return cnt
        h -= b
        cnt += 1

    return cnt + ceil(h / a)


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())
print(f(n, h, A, B))

Solution (Python):
import math
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)
throw_cand = []

for i in range(n):
    if b[i] >= a_max:
        throw_cand.append(b[i])
throw_cand.sort()

ans = 0
while h > 0:
    if len(throw_cand) > 0:
        kb = throw_cand.pop()
        h -= kb
        ans += 1
    else:
        ans += math.ceil(h / a_max)
        h -= math.ceil(h / a_max) * a_max

print(ans)

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

max_a = 0
for i in ab:
    max_a = max(i[0], max_a)

b = sorted([i[1] for i in ab if i[1] > max_a], reverse=True)

count = 0
for i in b:
    h -= i
    count += 1

    if h <= 0:
        print(count)
        exit()

print(count + (h - 1) // max_a + 1)

Solution (Python):
import math
from bisect import bisect_right, bisect_left
import sys
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for n in range(N):
    a[n], b[n] = map(int, input().split())
maximum = max(a)

sorted_b = sorted(b)

ans = 0

first = [sorted_b[i] for i in range(N - 1, bisect_left(sorted_b, maximum) - 1, -1)]
ans += len(first)
H_left = H - sum(first)

if H_left < 0:
    sorted_b = sorted(b, reverse=True)
    HP = H
    for i in range(N):
        HP -= sorted_b[i]
        if HP <= 0:
            print(i + 1)
            sys.exit()

ans += math.ceil(H_left / maximum)
print(ans)

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

A = []
B = []
attack = []
used = [0 for i in range(N)]

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

attack.sort()
attack = attack[::-1]
count = 0
for i in range(N*2):
    if H <= 0:
        print(count)
        exit()
    if attack[i][1] == 0:
        print(count + math.ceil(H/attack[i][0]))
        exit()
    H -= attack[i][0]
    count += 1

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

from operator import itemgetter
from math import ceil
AB.sort(key = itemgetter(1),reverse = True)

cut = max(AB,key = itemgetter(0))[0]
count = 0
for a,b in AB:
    if b < cut or H <= 0:
        break
    H -= b
    count += 1
if H > 0:
    count += ceil(H/cut)
    print(count)
else:
    print(count)

Solution (Python):
import numpy as np

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

a.sort()
to_swing = a[-1]
b.sort()

thr = np.searchsorted(b,a)[0]




if h % to_swing == 0:
    sw = h // to_swing
else:
    sw = h // to_swing+1

m = sw
for i in range(1,n+1-thr):
    h -= b[-i]
    if h > 0:
        if h%to_swing == 0:
            sw = h//to_swing
        else:
            sw = h//to_swing+1
        temp = i+sw
        if temp < m:
            m = temp
    else:
        temp = i
        if temp < m:
            m = temp
        

print(m)

Solution (Python):
n,h=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append([b,0]);a.append([c,1])
a.sort(reverse=1)
i=b=0
while h>0:
  if a[i][1]==1:h-=a[i][0];b+=1
  else:b+=(h-1)//a[i][0]+1;h=0
  i+=1
print(b)

Solution (Python):
from operator import itemgetter

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

h = H
strongest = dict(zip(["a", "b"], max(AB)))

count = 0
for a, b in sorted(AB, key=itemgetter(1), reverse=True):
	if strongest["a"] < b:
		h -= b
		count += 1
		if h <= 0:
			print(count)
			exit()
	else:
		break

count += (h // strongest["a"]) + (0 != (h % strongest["a"]))
print(count)

Solution (Python):
n,h=map(int,input().split())
a_m=0
b_list=[]
for i in range(n):
    a,b=map(int,input().split())
    a_m=max(a_m,a)
    b_list.append(b)
b_list.sort(reverse=True)
Sum=0
count=0
for i in range(n):
    if b_list[i]>=a_m:
        Sum=Sum+b_list[i]
        count=count+1
        if Sum>=h:
            print(count)
            import sys
            sys.exit()
    else:
        break
ans=count+((h-Sum)+a_m-1)//a_m
print(ans)

Solution (Python):
from math import ceil
 
N, H = map(int, input().split())
a, b = [], []
 
for _ in range(N):
    a_i, b_i = map(int, input().split())
    a.append(a_i)
    b.append(b_i)
 
max_a = max(a)
b = sorted(b, reverse=True)
ans = float('inf')
th_po = 0
 
for i in range(N):
    th_po += b[i]
    
    if H >= th_po:
        ans_cand = i + 1 + ceil((H - th_po) / max_a)
    else:
        ans_cand = i + 1
    
    ans = min([ans, ans_cand])
 
print(ans)

Solution (Python):
from math import ceil
from bisect import bisect_left


def solve(n, h):
    a = []
    b = []

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

    amax = max(a)
    b.sort()

    if n == 1:
        ans = ceil((h-b[n-1])/amax)+1

    else:
        over_amax = b[bisect_left(b, amax):]
        if h <= sum(over_amax):
            for j in range(n-1, -1, -1):
                h -= b[j]
                if h <= 0:
                    ans = n-j
                    break

        else:
            ans = ceil((h - sum(over_amax)) / amax) + len(over_amax)

    return ans


if __name__ == '__main__':
    n, h = map(int, input().split())
    print(solve(n, h))

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

ab.sort(key = lambda x:x[1],reverse = True)
ans = 0
damage = 0
flag = True
maxA = max(ab)
maxA = maxA[0]
for a,b in ab:
    if maxA > b:
        break
    damage += b
    ans += 1
    if damage >= H:
        flag = False
        break

if flag:
    if (H-damage)%maxA == 0:
        ans += (H-damage)//maxA
    else:
        ans += (H-damage)//maxA + 1
    print(ans)
    
else:
    print(ans)

Solution (Python):
N,H=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1],reverse=True)
a_M=max([ab[i][0] for i in range(N)])

ans =0
for a,b in ab:
    if b <= a_M:
        break
    H -= b
    ans += 1
    if H<=0:break
if H>0:
    ans += (H-1)//a_M+1
print(ans)

Solution (Python):
N,H=map(int,input().split())
ab=sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[1],reverse=True)
ab_M=max([ab[i][0] for i in range(N)])
ab_m=min([ab[i][1] for i in range(N) if ab[i][0]==ab_M])
cnt=0
flag=0
for i in range(N):
    if ab[i][1]<=ab_M:
        break
    elif flag==0 and ab[i]==[ab_M,ab_m]:
        flag=1
    else:
        H-=ab[i][1]
        cnt+=1
        if H<=0:
            break
if H>0:
    if H<=ab_m:
        print(cnt+1)
    else:
        print(cnt+1+(H-ab_m+ab_M-1)//ab_M)
else:
    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):
from math import ceil
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]

amax = 0
for i in range(N):
    amax = max(amax,ab[i][0])

B = []
for i in range(N):
    if ab[i][1]>amax:
        B.append(ab[i][1])
B.sort(reverse=True)
ans = 0
for b in B:
    H -= b
    ans += 1
    if H <= 0:
        break

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

print(ans)

Solution (Python):
import math

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

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

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

dmg = 0
for i in range(N):
    if B[i] <= p:
        index = i
        break
    else:
        dmg += B[i]
        if dmg >= H:
            print(i+1)
            exit()
    index = N

dmg = sum(B[:index])
ans = index+math.ceil((H-dmg)/p)
print(ans)

Solution (Python):


n, h = map(int, input().split())
a, b = 0, []
for _ in range(n):
    ai, bi = map(int, input().split())
    a = max(a, ai)
    b.append(bi)
b = list(sorted(b))

l, r = 0, n
while r-l > 0:
    mid = (l + r) // 2
    if b[mid] >= a:
        r = mid
    else:
        l = mid + 1
b = b[r:][::-1]
count = 0
for bi in b:
    h -= bi
    count += 1
    if h <= 0:
        break

if h > 0:
    count += h // a if h % a == 0 else h // a + 1

print(count)

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

class Sord:
  def __init__(self, a, b):
    self.hit = a
    self.throw = b

sords = []
maxhit = None
for a, b in (map(int, input().split()) for _ in range(N)):
  s = Sord(a, b)
  sords.append(s)
  if maxhit is None:
    maxhit = s
  elif s.hit > maxhit.hit or s.hit == maxhit.hit and s.throw > maxhit.throw:
    maxhit = s

cnt = 0
for s in sorted([s for s in sords if s.throw > maxhit.hit], key=lambda x:x.throw, reverse=True):
  H -= s.throw
  cnt += 1
  if H <= 0:
    break
else:
  cnt += H // maxhit.hit + (H % maxhit.hit != 0)*1

print(cnt)

Solution (Python):

import sys
from operator import itemgetter


def solve(N: int, H: int, A: "List[int]", B: "List[int]"):
    B.sort(reverse=True)
    maxA = max(A)

    D = 0
    res = 0

    for b in B:
        if b <= maxA:
            break

        D += b
        res += 1
        if D >= H:
            print(res)
            return

    res += (H-D)//maxA + (1 if (H-D)%maxA > 0 else 0)
    print(res)
    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()