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):
N,H = map(int,input().split())
ls = []
for i in range(N):
    a,b = map(int,input().split())
    ls.append([a,b])
ls.sort()
ls.sort(key=lambda x:-x[0])
mainkatana = ls.pop(0)
ls.sort(key=lambda x:-x[1])
ls.append([0,0])
ii = 0
while ls[0][1] >= mainkatana[0] and H > mainkatana[1]:
    ii += 1
    nage = ls.pop(0)
    H -= nage[1]
cut = max(0,-(-(H-mainkatana[1])//mainkatana[0]))
ii += cut
if H > 0:
    ii += 1
print(ii)

Solution (Python):
import math
import sys


def input():
    return sys.stdin.readline()[:-1]


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

max_a = 0
max_a_b = 0
AB = []
for _ in range(N):
    ab = list(map(int, input().split()))
    AB.append(ab)
    if max_a < ab[0]:
        max_a = ab[0]
        max_a_b = ab[1]
    elif max_a == ab[0] and max_a_b > ab[1]:
        max_a = ab[0]
        max_a_b = ab[1]

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

throw_sum = 0
ans = 0
for i in range(N):
    if max_a < AB[i][1]:
        throw_sum += AB[i][1]
        ans += 1
        if throw_sum >= H:
            print(ans)
            exit(0)

H -= throw_sum
ans += math.ceil(H/max_a)

print(ans)

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

B.sort(reverse=True)
Amax=max(A)
ans=0

for i in range(N):
    if B[i]<Amax:
        break

    H-=B[i]
    ans+=1
    if H<=0:
        break

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

print(ans)

Solution (Python):

def resolve():
    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_max = max(A)

    
    B = [b for b in B if a_max < b]
    B.sort(reverse=True)

    cnt = 0
    for b in B:
        if H <= 0:
            print(cnt)
            return
        H -= b
        cnt += 1

    cnt += -(-H // a_max)
    print(cnt)


if __name__ == "__main__":
    resolve()

Solution (Python):

from math import floor, ceil, sqrt, factorial, log, gcd, log10
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement, chain
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
from copy import copy, deepcopy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)


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






n, h = LI()
a, b = [], []

for i in range(n):
    A, B = LI()
    a.append(A)
    b.append(B)
a_max = max(a)
b = list(filter(lambda x: x >= a_max, b))
b.sort(reverse=True)
life = 0
cnt = 0
for x in b:
    life += x
    cnt += 1
    if life >= h:
        print(cnt)
        break
if life < h:
    cnt += (h - life - 1) // a_max + 1
    print(cnt)

Solution (Python):
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
max_a = max(a)
b.sort(reverse=True)
cnt = 0
for i in range(n):
    if b[i] < max_a:
        break
    h -= b[i]
    cnt += 1
    if h <= 0:
        break
if h > 0:
    cnt += (h - 1) // max_a + 1
print(cnt)

Solution (Python):
import bisect
N, H = map(int, input().split())
B = [0] * N
m = 0
for i in range(N):
  a, b = list(map(int, input().split()))
  B[i] = b
  m = max(m, a)
  
B = sorted(B)
index = bisect.bisect_left(B, m)


over = sum(B[index:])
if over >= H:
  
  now = 0
  i = 1
  while now < H:
    now += B[-i]
    i += 1
  print(i - 1)  
else:
  H -= over
  ans = N - index
  ans += int(H / m)
  if H % m != 0:
    ans += 1
  print(ans)

Solution (Python):
import math

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

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

a_max = A[0]

ans = 0
bi = 0
while H > 0:
    if bi < N and a_max <= B[bi]:
        ans += 1
        H -= B[bi]
        bi += 1
    else:
        ans += math.ceil(H / a_max)
        break
print(ans)

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

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

once=[]
infinity=[]

for i in range(n):
  a,b=map(int,input().split())
  once.append(b)
  infinity.append(a)
  
once.sort(reverse=True)

pin=max(infinity)

once2=[]
for i in range(n):
  if once[i]>pin:
    once2.append(once[i])
  
  else:
      break

ans=0
for i in once2:
    ans+=1
    h-=i
    if h<=0:
        print(ans)
        exit()

ans+=math.ceil(h/pin)


print(ans)

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

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

once=[]
infinity=[]

for i in range(n):
  a,b=map(int,input().split())
  once.append(b)
  infinity.append(a)
  
once.sort(reverse=True)

pin=max(infinity)

once2=[]
for i in range(n):
  if once[i]>pin:
    once2.append(once[i])
  
  else:
      break

ans=0
for i in once2:
    ans+=1
    h-=i
    if h<=0:
        print(ans)
        exit()

ans+=math.ceil(h/pin)


print(ans)

Solution (Python):
n,h=map(int,input().split())
a=[]
b=[]
for i in range(n):
  a_,b_=map(int,input().split())
  a.append(a_)
  b.append(b_)
  
use_a=max(a)
kouho=[]
for i in b:
  if i>=use_a:
    kouho.append(i)
kouho.sort(reverse=True)

ans=0
cnt=0
for i in kouho:
  cnt+=i
  ans+=1
  if cnt>=h:
    print(ans)
    exit()
    
if (h-cnt)%use_a==0:
  print(ans+(h-cnt)//use_a)
else:
  print(ans+(h-cnt)//use_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)

max_a = max(A)
B.sort(key=lambda b:-b) 

ans = 0
for b in B:
    if b < max_a:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()
ans += (H-1) // max_a + 1 
print(ans)

Solution (Python):
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():


    n, h= LI()
    huri = [0 for _ in range(n)]
    nage = [0 for _ in range(n)]
    use = []
    
    for i in range(n):
        huri[i], nage[i] = LI()

    mx = max(huri)

    for katana in nage:
        if katana >= mx:
            use.append(katana)

    use.sort(reverse=True)
    ans = 0
    for used in use:
        h -= used
        ans += 1
        if h<=0:
            break

    if h>0:
        ans += (h+mx-1)//mx

    print(ans)



main()

Solution (Python):
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b = map(int,input().split())
    A = max(A,a)
    B.append(b)
B = sorted(B, reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

ans = 0
for i in range(len(B)):
    H -= B[i]
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H -1)//A + 1)

Solution (Python):

def main():
    with open(0) as f:
        N, H = map(int, f.readline().split())
        ab = list(map(int, f.read().split()))
    max_slash = max(ab[0::2])
    throw = sorted([x for x in ab[1::2] if x > max_slash], reverse=True)
    cnt = 0
    for t in throw:
        if H <= 0:
            break
        H += -t
        cnt += 1
    if H > 0:
        cnt += (H+max_slash-1)//max_slash
    print(cnt)

main()

Solution (Python):
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b=map(int,input().split())
    A=max(A,a)
    B.append(b)
B.sort(reverse=True)
ans=(H-1)//A+1
for i in range(N):
    H-=B[i]
    if H<=0:
        ans=min(ans,i+1)
        break
    ans=min(ans,(H-1)//A+1+i+1)
print(ans)

Solution (Python):
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b=map(int,input().split())
    A=max(A,a)
    B.append(b)
B.sort(reverse=True)
ans=(H-1)//A+1
for i in range(N):
    H-=B[i]
    if H<=0:
        ans=min(ans,i+1)
        break
    ans=min(ans,(H-1)//A+1+i+1)
print(ans)

Solution (Python):
n,h = map(int,input().split())
s1 = []
s2 = []
for _ in range(n):
  a, b = map(int,input().split())
  s1.append(a)
  s2.append(b)
maxa = max(s1)
s2.sort(key=lambda x:-x)
ans = 0
for s2i in s2:
  if s2i > maxa:
    ans += 1
    h -= s2i
  if h <= 0:
    break
if h > 0:
  if h % maxa == 0:
    ans += h // maxa
  else:
    ans += h // maxa + 1
  print(ans)
else:
  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)
A.sort(reverse=True)
B.sort(reverse=True)

"""
a_max, a_max, ..., a_max, b, b, ..., b　となる

a_maxより強いbは強い順に投げておいて、まだ倒せなかったらa_maxを振ると考える
実際には計算された回数だけa_maxを振り、その後bを投げれば良い
"""

cnt = 0
a_max = max(A)

for b in B:
    if b < a_max:
        break
    H -= b
    cnt += 1
    if H <= 0:
        break

if H > 0:
    if H % a_max == 0:
        cnt += H // a_max
    else:
        cnt += H // a_max + 1

print(cnt)

Solution (Python):

import bisect
import sys
import math
sys.setrecursionlimit(10**6)


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

a = []
b = []
ab = []
for i in range(n):
    a_tmp, b_tmp = list(map(int, input().split()))
    a.append(a_tmp)
    b.append(b_tmp)
    

a_max = max(a)
b.sort()

index = bisect.bisect_right(b, a_max)

ans = 0
for i in reversed(range(index, n)):
    h -= b[i]
    ans += 1
    if h <= 0:
        break


if h > 0:
    ans += math.ceil(h/a_max)

print(ans)

Solution (Python):
import math

n, h = map(int, input().split())
ab = [None] * n
for i in range(n):
    ab[i] = tuple(map(int, input().split()))

amax = max([m[0] for m in ab])

ans = 0
for a, b in sorted(ab, key=lambda m: -m[1]):
    if b <= amax:
        break
    h -= b
    ans += 1
    if h <= 0:
        print(ans)
        exit(0)

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

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

for i in range(n):
    A,B = map(int,input().split())
    a = max(A,a)
    b.append(B)
    
b = sorted(b)[::-1]

for i in range(n):
    if 0 < h and a < b[i]:
        h -= b[i]
        ans = i + 1
        
    else:
        ans = i
        break
        
if 0 < h:
    ans += -(-h//a)
    
print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy,bisect
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time, copy
from operator import itemgetter

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  


N, H = na()
maxA = -1
bbb = []
for i in range(N):
    a, b = na()
    maxA = max(maxA, a)
    bbb.append(b)
bbb.sort(reverse=True)
ct = 0
now = 0
for i in range(N):
    if bbb[i] <= maxA:
        break
    now += bbb[i]
    ct += 1
    if now >= H:
        print(ct)
        sys.exit()

res = H - now
if res % maxA == 0:
    print(ct + res // maxA)
else:
    print(ct + res // maxA + 1)

Solution (Python):
n, h = map(int, input().split())
bi_str = []
a_big = 0
ans = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] > a_big:
        a_big = a[i]

for i in range(n):
    if b[i] > a_big:
        bi_str.append(b[i])
bi_str.sort(reverse=True)


if h <= sum(bi_str):
    for i in bi_str:
        if h > 0:
            h -= i
            ans += 1
        else:
            break
else:
    h -= sum(bi_str)
    ans += len(bi_str)
    ans += -(-h//a_big)
    '''
    if round(h/a_big) == h//a_big:
        ans += h//a_big
    else:
        ans += h//a_big+1
        '''

print(ans)

Solution (Python):
import math
from typing import List, Any


def read_int() -> int:
    return int(input().strip())


def read_ints() -> List[int]:
    return list(map(int, input().strip().split(' ')))

def ceil(a, b):
    if a%b == 0:
        return a//b
    return a//b+1

def solve() -> Any:
    N, H = read_ints()
    A = 0
    answer = 0
    B = []
    for _ in range(N):
        a, b = read_ints()
        A = max(A, a)
        B.append(b)
    B.sort()
    while B and B[-1] > A:
        H -= B.pop()
        answer += 1
        if H <= 0:
            return answer
    return answer+ceil(H, A)


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

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

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

B = sorted(B, reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

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

ans = 0
attack_sum = 0
for i in range(N):
    if B_sorted[i] >= A_sorted[0]:
        if H > attack_sum:
            attack_sum += B_sorted[i]
            ans += 1
        else:
            print(ans)
            exit(0)
    else:break
ans += - (-(H - attack_sum) // A_sorted[0])
print(ans)

Solution (Python):
n,h=map(int,input().split())
a,b=[],[]

for i in range(n):
  inp=list(map(int,input().split()))
  a.append(inp[0])
  b.append(inp[1])

am=max(a)
b.sort()
b.reverse()
c=0
for i in b:
  if i<am:
    break
  c+=1
  h-=i
  if h<=0:
    break
c+=max((h-1)//am+1,0)
print(c)

Solution (Python):
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    return C

N,H=mint()
A=[]
B=[]
for _ in range(N):
    a,b=mint()
    A.append(a)
    B.append(b)
a=max(A)
B.sort(reverse=True)
ans=0
for b in B:
    if b<a:
        break
    H-=b
    ans+=1
    if H<=0:
        print(ans)
        exit()
print(ans+(H-1)//a+1)

Solution (Python):
import math

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

A=[]
B=[]
for n in range(N):
    a,b = list(map(int,input().split()))
    A.append(a)
    B.append(b)
    
A.sort(reverse=True)
B.sort(reverse=True)
A,B

a_max=A[0]

B_=[]
for b in B:
    if b < a_max:
        break
    B_.append(b)
B=B_

B_sum = [0]
for b in B:
    B_sum.append(B_sum[-1]+b)

ans = 0
for b_sum_idx,b_sum in enumerate(B_sum):
    if b_sum >= H:
        ans = b_sum_idx
        break
        
    ans = b_sum_idx
H = max(0,H - b_sum)

ans += math.ceil(H/a_max)

print(ans)

Solution (Python):
N, H = map(int, input().split())
A = []
B = []
for i in range(N):
  a, b = map(int, input().split())
  A.append(a)
  B.append(b)
A.sort(reverse = True)
B.sort(reverse = True)
count = 0
for b in B:
  if b > A[0]:
    H -= b
    count += 1
  else:
    break
  if H <= 0:
    break
if H > 0:
  count += (H + A[0] - 1) // A[0]
print(count)

Solution (Python):
import heapq as hq
from itertools import accumulate
from math import ceil
N, H = map(int, input().split())
ab = [tuple(map(int,input().split())) for _ in range(N)]
ab.sort(key=lambda x:x[1], reverse=True)
ab.sort(key=lambda x:x[0], reverse=True)
ma, mb = ab[0]
q = [ab[i][1] for i in range(1, N)]
q.sort(reverse=True)
ans = float("inf")
acc = [0]+list(accumulate(q, lambda x,y:x+y))
for l in range(len(q)+1):
    h = H
    cnt = l
    h -= acc[l]
    if h <= 0:
        ans = min(ans, cnt)
        continue
    h -= mb
    cnt += 1
    if h <= 0:
        ans = min(ans, cnt)
        continue
    cnt += ceil(h/ma)
    ans = min(ans, cnt)
print(ans)

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

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

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

ans = 0
cnt = 0
while(1):
    if H<=0:
        print(ans)
        exit()
    if cnt==len(B):
        break
    if A[0]>=B[cnt]:
        break
    H-=B[cnt]
    cnt+=1
    ans+=1

if H%A[0]==0:
    res = H//A[0]
else:
    res = H//A[0]
    res += 1

print(ans+res)

Solution (Python):
n,h=map(int,input().split())
aa=[]
bb=[]
for _ in range(n):
  a,b=map(int,input().split())
  aa.append(a)
  bb.append(b)
  
maxa=max(aa)
bb.sort(reverse=True)
nage=0
ch=0
for i in range(n):
  if bb[i]>=maxa:
    nage+=bb[i]
    ch+=1
  else:
    break
    
if h>nage:
  rest=h-nage
  ch1=0
  if rest%maxa==0:
    ch1+=rest//maxa
  else:
    ch1+=(rest//maxa+1)
  print(ch1+ch)
  
else:
  ans=0
  hp=0
  for j in range(n):
    if hp>=h:
      break
    else:
      ans+=1
      hp+=bb[j]
  print(ans)

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

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

A.sort(reverse=True)
B.sort(reverse=True)
ans = 0
tmp = 0
cnt = 0
while(1):
    if tmp>=H:
        print(ans)
        exit()
    if cnt==len(B):
        break
    if A[0]>=B[cnt]:
        break
    tmp += B[cnt]
    ans += 1
    cnt += 1

res = H - tmp
if res%A[0]==0:
    ans += res//A[0]
else:
    ans += res//A[0]
    ans += 1
print(ans)

Solution (Python):
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]

import string

def main():
    N,H = i_map()
    l = []
    for _ in range(N):
        a,b = i_map()
        l.append([a,b])
    t = [list(i) for i in zip(*l)]
    ans = 0

    M = max(t[0])
    throw = 0
    for i in sorted(t[1], reverse=True):
        if i > M:
            throw += i
            H -= i
            ans += 1
            if H <= 0:
                print(ans)
                exit()
    i = t[0].index(M)
    
    if H%M == 0:
        ans += H//M
    else:
        ans += H//M+1
    print(ans)


if __name__=="__main__":
    main()

Solution (Python):
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B = reversed(sorted(B))
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))

Solution (Python):



N, H = (int(x) for x in input().split())

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

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

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

if (H > 0):
    ret += H // AMax
    if H % AMax != 0:
        ret += 1
print(ret)

Solution (Python):
from math import ceil
n, h, *AB = map(int, open(0).read().split())
a = max(AB[::2])
B = sorted(b for b in AB[1::2] if a < b)[::-1]
c = 0
for b in B:
    h -= b
    c += 1
    if h <= 0:
        break
else:
    c += ceil(h / a)
print(c)

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

a_sort = sorted(lis, reverse=True)

b_sort = sorted(lis, key=lambda x:x[1], reverse=True)

cnt = 0
furu = a_sort[0][0]

for nage in b_sort:
    if nage[1] > furu:
        h -= nage[1]
        cnt += 1
    else:
        break

    if h <= 0:
        break

if h <= 0:
    print(cnt)
else:
    plus = int(math.ceil(h/furu))
    cnt += plus
    print(cnt)

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

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

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

wield = 0
bs = []

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

    if a > wield:
        wield = a

    bs.append(b)

throw = []

for i in range(n):
    if bs[i] > wield:
        throw.append(bs[i])

total = sum(throw)

if total > h:
    throw = sorted(throw, reverse=True)

    total = 0
    ind = 0
    while total < h:
        total += throw[ind]
        ind += 1

    print(ind)
else:
    print((h-total+wield-1)//wield + len(throw))

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

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

throw.sort(reverse=True)
throw_cam = []
for i in range(n):
    if cut > throw[i]:
        break
    if i == 0:
        throw_cam.append(throw[0])
    else:
        throw_cam.append(throw[i] + throw_cam[i-1])

if throw_cam[len(throw_cam)-1] < h:
    rh = h - throw_cam[len(throw_cam)-1]
    if rh % cut == 0:
        print(len(throw_cam) + rh//cut)
    else:
        print(len(throw_cam) + rh//cut + 1)
else:
    for i in range(len(throw_cam)):
        d = throw_cam[i]
        if d >= h:
            print(i+1)
            break

Solution (Python):
N,H = map(int,input().split())
K = [list(map(int,input().split())) for n in range(N)]
A = max(k[0] for k in K)
B = sorted(b for a,b in K if A<b)
C = 0

while 0<H and B:
  H-=B.pop()
  C+=1

print(C-(-max(0,H)//A))

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

a.sort(reverse=True)
b.sort(reverse=True)
b_select = []
for i in range(n):
    if b[i] < a[0]:
        break
    else:
        b_select.append(b[i])

if sum(b_select) >= h:
    for i in range(n):
        h -= b_select[i]
        if h <= 0:
            break
    counter = i + 1
else:
    h -= sum(b_select)
    counter = len(b_select)
    counter += (h + a[0] - 1) // a[0]

print(counter)

Solution (Python):
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    

Throw = sorted([th for th in Throw if th > slash], reverse=True)
dmg, cnt = 0, 0
for throw in Throw:
    if dmg >= H: break
    dmg += throw
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)

Solution (Python):
N, H = map(int, input().split())
slash = 0
Throw = []
for _ in range(N):
    a, b = map(int, input().split())
    slash = max(slash, a)
    if b > a: Throw.append(b)    

import heapq as hq
Throw = [-th for th in Throw if th > slash]
hq.heapify(Throw)

dmg, cnt = 0, 0
while len(Throw) != 0:
    if dmg >= H: break
    dmg += -hq.heappop(Throw)
    cnt += 1
if dmg < H:
    from math import ceil
    cnt += ceil((H-dmg)/slash)
print(cnt)

Solution (Python):
N,H=map(int,input().split())
As=[]
Bs=[]
for _ in range(N):
    a,b=map(int,input().split())
    As.append(a)
    Bs.append(b)
ans=0
max_a=max(As)
sort_Bs=sorted(Bs,reverse=True)
new_Bs=[]
for b in sort_Bs:
    if b>max_a:
        new_Bs.append(b)
for b in new_Bs:
    H-=b
    ans+=1
    if H<=0:
        break
if H>0:
    if H%max_a==0:
        ans+=(H//max_a)
    else:
        ans+=(H//max_a+1)
print(ans)

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

maxa=max(A)
C=[]
B.sort(reverse=True)
ans=0
for ele in B:
    if ele<maxa:
        break
    ans+=1
    h-=ele
    if h<=0:
        break
if h>0:
    ans+=(h+maxa-1)//maxa
print(ans)

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)

a_max = 0
for i in range(N):
    a_max = max(a_max, AB[i][0])

cnt = 0
sum_throw = 0
for i in range(N):
    if AB[i][1] > a_max:
        sum_throw += AB[i][1]
        cnt += 1

        if sum_throw >= H:
            print(cnt)
            exit()


rem = H - sum_throw

q, r = divmod(rem, a_max)
if r == 0:
    cnt += q
else:
    cnt += q + 1

print(cnt)

Solution (Python):
import math

n, h = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(n)]

aL = []
bL = []
for a, b in abL:
    aL.append(a)
    bL.append(b)
aL = sorted(aL)
bL = sorted(bL)

aMax = max(aL)
ans = 0
while h != 0:
    if h <= 0:
        break
    if len(bL) == 0 or bL[-1] < aMax:
        ans += math.ceil(h / aMax)
        break
    ans += 1
    h -= bL.pop()

print(ans)

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

B.sort(reverse=True)
ans = 0

for b in B:
    if max_attack <= b:
        H -= b
        ans += 1
        if H <= 0:
            break
    else:
        break

if 0 < H:
    if H%max_attack == 0:
        ans += H//max_attack
    else:
        ans += 1+H//max_attack
print(ans)

Solution (Python):
from math import ceil
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=sorted(A)
B=sorted(B, reverse=True)
amax=max(A)

ans=0

for i in range(N):
    b=B[i]
    if b>amax:
        H-=b
        ans+=1
        if H<=0:
            break
    else:
        break
if H>0:
    ans+=ceil(H/amax)
print(ans)

Solution (Python):
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,H = MI()
X = []
for i in range(N):
    a,b = MI()
    X.append((a,0))
    X.append((b,1))

X.sort(reverse=True)

i = 0
ans = 0
while H > 0:
    x,y = X[i]
    if y == 1:
        H -= x
        i += 1
        ans += 1
    else:
        ans += (H+x-1)//x
        break

print(ans)

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, H = mapint()
from heapq import heappop, heappush
Q = []
for _ in range(N):
    a, b = mapint()
    heappush(Q, (-a, 'N'))
    heappush(Q, (-b, 'L'))

ans = 0
while H>0:
    v, ty = heappop(Q)
    v *= -1
    if ty=='N':
        print(ans-(-H//v))
        exit()
    H -= v
    ans += 1
print(ans)

Solution (Python):
from heapq import*
n,h=map(int,input().split())
katanas=[]
for _ in range(n):
  a,b=map(int,input().split())
  heappush(katanas,(-a,0))
  heappush(katanas,(-b,1))
  
ans=0
t=0
for i in range(10**9):
  tmp,idx=heappop(katanas)
  if idx==1:
    
    
    h=h-(-tmp)
    t+=1
    if h<=0:
      print(t)
      exit()
  else:
    
    
    t+=(h+(-tmp)-1)//(-tmp)
    print(t)
    exit()

Solution (Python):
from heapq import heappop, heappush

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.sort()
b.sort()
q = []
for i in range(N):
    if b[i] > a[-1]:
        heappush(q, -b[i])

ans = 0
while q:
    H += heappop(q)
    ans += 1
    if H <= 0:
        print(ans)
        exit()

print(ans + (H+a[-1]-1)//a[-1])