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())
alist = []
blist = []
for i in range(N):
    A, B = map(int, input().split())
    alist.append(A)
    blist.append(B)

maxa = max(alist)
blist = list(filter(lambda el: el > maxa, blist))

def mergesort(l):
    def merge(left, right):
        result = []
        while left and right:
            if left[0] <= right[0]:
                result.append(left.pop(0))
            else:
                result.append(right.pop(0))
        return result + left + right

    length = len(l)
    if length <= 1:
        return l
    middle = length // 2
    return merge(mergesort(l[:middle]), mergesort(l[middle:]))

blist = mergesort(blist)
blist.reverse()

sum_for_h = 0
ans = 0
for i in blist:
    sum_for_h += i
    ans += 1
    if sum_for_h >= H:
        print(ans , flush=True)
        exit()

anum = (H-sum_for_h) / maxa
import math
anum = math.ceil(anum)
print(ans + anum, flush=True)

Solution (Python):
import sys
from heapq import *
from math import ceil
from itertools import accumulate
def input(): return sys.stdin.readline().strip()


def main():
    n, h = map(int, input().split())
    cut = []
    throw = []
    for i in range(n):
        a, b = map(int, input().split())
        cut.append(a)
        throw.append(b)
    cut_max = max(cut)
    throw.sort(reverse=True)
    throw_sum = [0] + list(accumulate(throw))

    loss = set()
    ans = 10**10
    for t in range(n + 1):
        rem = max(0, h - throw_sum[t])
        ans = min(ans, t + ceil(rem / cut_max))
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n)]
ab = sorted(ab, key=lambda ab: (-ab[0], ab[1]))  
maxa = ab[0][0]
maxa_b = ab[0][1]
ab[0][0] = 0
ab[0][1] = 0



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

ans = 0
for i in range(n-1):
    if h <= 0:
        print(ans)
        break

    if h <= maxa_b:
        ans += 1
        print(ans)
        break

    if maxa < ab[i][1]:
        h -= ab[i][1]
        ans += 1
    else:
        h -= maxa
        ans += 1
    
else:
    
    ans += 1
    h -= maxa_b
    if h <= 0:
        print(ans)
    else:
        if h % maxa == 0:
            ans += h//maxa
        else:
            ans += h//maxa+1
        print(ans)

Solution (Python):
import math

n, h = map(int, input().split())
b = [0] * n
maxa = 0
for i in range(n):
    x, y = map(int, input().split())
    maxa = max(x, maxa)
    b[i] = y
b.sort(reverse = True)
ans = 0
for i in range(n):
    if b[i] < maxa:
        break
    h -= b[i]
    ans += 1
    if h <= 0:
        break
if not h <= 0:
    ans += math.ceil(h / maxa)
print(ans)

Solution (Python):
from math import ceil
n, h = map(int, input().split())
data1, data2 = [], []
for i in range(n):
    a, b = map(int, input().split())
    data1.append([a, b])
    data2.append([a, b])

data1 = sorted(data1, key = lambda x: x[0], reverse = True)
data2 = sorted(data2, key = lambda x: x[1], reverse = True)
ans = 0
while h > 0 and data1[0][0] < data2[0][1]:
    h -= data2[0][1]
    ans += 1
    del data2[0]
    if len(data2) == 0:
        break
ans += ceil(max(0, h) / data1[0][0])
print(ans)

Solution (Python):
from heapq import heappop,heappush
n,h=map(int,input().split())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  heappush(a,(-x,1))
  heappush(a,(-y,0))
ans=0
while h>0:
  x,y=heappop(a)
  if y:
    ans+=(h-x-1)//(-x)
    break
  else:
    h+=x
    ans+=1
print(ans)

Solution (Python):
import sys
from collections import deque

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 998244353


def resolve():
    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(reverse=True)
    que = deque(B)

    res = 0
    while h > 0:
        if que and MAX_A < que[0]:
            damage = que.popleft()
            h -= damage
            res += 1
        else:
            res += (h + MAX_A - 1) // MAX_A
            h = 0

    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):
import math

n,h = map(int,input().split())
s = []
max_a = 0
for i in range(n):
    a,b = map(int,input().split())
    max_a = max(a,max_a)
    s.append((b,a))

if max_a >= h:
    print(1)
    exit()

s.sort(reverse=True)
ans = 10**9
i = 0
while h > 0 and i < n:
    h -= s[i][0]
    c = max(0,math.ceil(h/max_a))
    ans = min(i+c+1,ans)
    i += 1

print(ans)

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

A = []
B = []
amax = -1
bmax = -1

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

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

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

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            print(ans)
            exit(0)

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N, H = LI()
    a = []
    b = []
    for _ in range(N):
        ab = LI()
        a.append(ab[0])
        b.append(ab[1])
    b.sort(reverse=True)
    a_max = max(a)

    
    
    ans = 0
    i = 0
    while i < N and H > 0 and b[i] > a_max:
        H -= b[i]
        i += 1
        ans += 1

    if 0 < H:
        ans += (H - 1) // a_max + 1

    print(ans)

if __name__ == '__main__':
    resolve()

Solution (Python):
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n, h = MAP()
a = [0]*n
b = [0]*n

for i in range(n):
    a[i], b[i] = MAP()

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

ans = 0
i = 0
while i < n and b[i] > a[0] and h > 0:
    ans += 1
    h -= b[i]
    i += 1

if h > 0:
    ans += (h+a[0]-1)//a[0]

print(ans)

Solution (Python):
(n,h),*ab = [list(map(int, s.split())) for s in open(0)]

mxa = max([a for a, b in ab])
bb = sorted([b for a, b in ab if b>mxa],reverse=True)

ans = 0
for b in bb:
    h-=b
    ans += 1
    if h<=0:
        break
if h>0:
    ans += (0--h//mxa)
print(ans)

Solution (Python):
from math import *
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)
aa=max(a)
b.sort(reverse=True)
ans=0
for i in range(n):
    if b[i]>aa:
        h-=b[i]
        ans+=1
        if h<=0:
            print(ans)
            exit()
print(ans+ceil(h/aa))

Solution (Python):
n,h=map(int, input().split())
a_l=[]
b_l=[]
for _ in range(n):
    a,b=map(int, input().split())
    a_l.append(a)
    b_l.append(b)
a_l.sort(reverse=True)
b_l.sort(reverse=True)
a_max=max(a_l)

b_strong=[]
for b_i in b_l:
    if b_i>a_max:
        b_strong.append(b_i)

cnt=0
for b_s in b_strong:
    if h>0:
        h-=b_s
        cnt+=1
    else:
        break

if h>0:
    cnt+=(h-1)//a_max+1

print(cnt)

Solution (Python):
import math
n, h = map(int, input().split())
AB = [[0,0] for _ in range(n)]
mxA, mxB = 0, 0
for i in range(n):
    AB[i] = list(map(int,input().split()))
    if (mxB==0) or (mxA == AB[i][0] and mxB > AB[i][1]) or (mxA < AB[i][0]):
        mxA, mxB = AB[i][0], AB[i][1]

ans = 0
AB.sort(key=lambda x: x[1], reverse=True)
mxAi = AB.index([mxA,mxB])
for i in range(n):
    if i!=mxAi and AB[i][1]>mxA and h>0:
        h -= AB[i][1]
        ans += 1
if h>0:
    ans += max(1, 1+math.ceil((h-mxB)/mxA))
print(ans)

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

Solution (Python):
import math
import bisect

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

alist = []
blist = []

for n in range(N):
    a, b = map(int, input().split())
    alist.append(a)
    blist.append(b)

a_max = max(alist)

b_th_list = []
for b in blist:
    if b > a_max:
        b_th_list.append(b)

num_th = len(b_th_list)
H_res = H - sum(b_th_list)

if H_res <= 0:
    b_th_list.sort(reverse=True)
    sum_d = 0
    ans = 0
    for b in b_th_list:
        ans += 1
        sum_d += b
        if sum_d >= H:
            break
    print(ans)

else:
    num_cut = math.ceil(H_res/a_max)
    print(num_cut + num_th)

Solution (Python):
import sys
from collections import deque

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():

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

    ab = deque(sorted(ab, reverse=True))

    count = 0
    while H > 0:
        d, x = ab.popleft()
        if x == 1:
            H -= d
            count += 1
        else:
            count += -(-H // d)
            break

    print(count)


if __name__ == '__main__':
    main()

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 = sorted(a, reverse=True)
b = sorted(b, reverse=True)
c = 0
j = 0
while j<n:
    if b[j] > a[0]:
        c += b[j]
    else:
        break
    j += 1
    if c >= h:
        break

if c < h:
    j += -(-(h-c)//a[0])
print(j)

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 = sorted(a)[-1]
b_des = sorted(b, reverse=True)

res = 0
sum_b = 0
for bi in b_des:
    if bi <= a_max:
        break
    else:
        H -= bi
        res += 1
    if H <= 0:
        break

if H > 0:
    res += int(math.ceil(H / a_max))

print(res)

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

v = max(a)
b.sort(reverse=True)
i = 0
while i < n and b[i] > v and h > 0:
    h -= b[i]
    i += 1

if h <= 0:
    print(i)
else:
    print(i + (h + v - 1) // v)

Solution (Python):

import sys


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    from math import ceil
    c = sorted([(bb, False) for bb in b] + [(aa, True) for aa in a], reverse=True)
    ans = 0
    for cc, f in c:
        if f:
            return ans + ceil(H / cc)
        ans += 1
        H -= cc
        if H <= 0:
            return ans


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))
    print(solve(N, H, a, b))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

Solution (Python):
import math
def main():
    n,h = map(int,input().split())
    A =0
    BA = []
    for i in range(n):
        a,b = map(int,input().split())
        BA.append([b,a])
        A = max(A,a)
    BA.sort(reverse=True)
    cnt = 0
    for i in range(n):
        if BA[i][0]> A:
            h -= BA[i][0]
            cnt += 1
            if h <= 0:
                break
    
    if h>0:
        cnt += math.ceil(h/A)
    print(cnt)

main()

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

import bisect,math


b=sorted(b)
index = bisect.bisect_left(b,max(a))

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

ans=math.ceil(h/max(a))+cnt

print(ans)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *



N, H = MAP()

AB = [LIST() for _ in range(N)]
a, b = zip(*AB)
b = list(b)
a_max = max(a)

ans = 0
b.sort()

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *



N, H = MAP() 
ab = [LIST() for _ in range(N)]

a, b = zip(*ab)
b = list(b)

b.sort()
A = max(a)

B = b[bisect(b, A):][::-1]
if B:
	B = list(accumulate(B))
else:
	B = [0]


if H <= B[-1]:
	print(bisect_left(B, H)+1)
else:
	if B[-1] == 0:
		print(ceil(H/A))
	else:
		print(len(B) + ceil((H-B[-1])/A))

Solution (Python):
import math
n, h = map(int, input().split())
shake =[]
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    shake.append(a)
    throw.append(b)

max_shk = max(shake)
sort_thr = sorted(throw, reverse = True)


count = 0
for i in sort_thr:
    if max_shk < i:
        h = h - i
        count += 1
        if h <= 0:
            break
if h > 0:
    count += math.ceil(h / max_shk)
print(count)

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()
B.sort()
from bisect import bisect_right
val = A[-1]
idx = bisect_right(B,val)
B= B[idx:]
cnt = 0
while B and H:
    H-=B.pop()
    cnt += 1
    if H<=0: print(cnt);exit()
cnt += H//val
cnt += 1 if H%val else 0
print(cnt)

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


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


def solve(N, H, A, B):
    
    amax = max(A)
    B.sort(reverse=True)
    ans = 0
    for b in B:
        if amax >= b:
            break
        H -= b
        ans += 1
        if H <= 0:
            break
    if H > 0:
        ans += H // amax
        if H % amax > 0:
            ans += 1 
    return ans


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

ans=0
B.sort(reverse=True)
for i in range(n):
	if B[i]>w:
		h-=B[i]
		ans+=1
		if 1>h:
			print(ans)
			exit()
ans+=h//w
if h%w==0:
	print(ans)
else:
	print(ans+1)

Solution (Python):
from bisect import bisect
import math

N, H = map(int, input().split())
A = []
B = []

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

aM = max(A)
B.sort()

r = N - bisect(B, aM)
cnt = 0

for i in range(r):
  H -= B[-1-i]
  cnt += 1
  if H <= 0:
    print(cnt)
    break
  
if H > 0:
  print(math.ceil(H/aM) + cnt)

Solution (Python):
n, h = map(int,input().split())
throw = []
attack = 0
for _ in range(n):
    a, b = map(int,input().split())
    throw.append(b)
    attack = max(attack, a)
throw.sort(reverse=True)

ans = 0
for t in throw:
    if t > attack:
        ans += 1
        h -= t
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += -(-h//attack)

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)

MA=max(A)
ans=0
B.sort()
k=-1

while B[k]>MA:
    H-=B[k]
    k-=1
    ans+=1
    if H<=0:
        break
    if k<-N:
        break
if H>=0:
    ans+=-(-H//MA)

print(ans)

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




def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


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


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))





def main():
	n,h=MI()
	li=[LI() for _ in range(n)]
	
	li.sort(key=lambda x:x[1])
	
	li.sort(key=lambda x:x[0],reverse=True)
	
	
	a=li[0][0]
	b=li[0][1]
	
	li=li[1:]
	li.sort(key=lambda x:x[1],reverse=True)
	
	A=[]
	
	for i in range(n-1):
		if li[i][1]>a:
			A.append(li[i][1])
		else:
			break
	
	
	ans=0
	
	for i in A:
		if h>0:
			ans+=1
			h-=i
		else:
			print(ans)
			exit()
	else:
		if h<=0:
			print(ans)
		elif h<=b:
			print(ans+1)
		else:
			print(ans+1-(b-h)//a)
		
	
	
	

if __name__=="__main__":
	main()

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

l_b = sorted(l, key=lambda x: x[1])
l = sorted(l_b, reverse=True, key=lambda x: x[0])
c_a = 0
c_b = 0
b_sum = 0

for i in range(n-1, -1, -1):
  if l_b[i][1] >= l[0][0]:
    b_sum += l_b[i][1]
    h -= l_b[i][1]
    c_b += 1
    if h <= 0:
      print(c_b)
      exit()
import math
c_a = math.ceil((h2 - b_sum) / l[0][0])


print(c_a+c_b)

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

max_a = max(arr_a)
arr_b.sort(reverse=True)

ans = 0
for b in filter(lambda x: x > max_a, arr_b):
    ans += 1
    h -= b
    if h <= 0:
        break
else:
    ans += 0 - -h//max_a

print(ans)

Solution (Python):
from bisect import bisect_left, bisect_right  
from math import ceil, floor

N, H = map(int, input().split())
A, B = [], []

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

amax = max(A)
B = sorted(B)
ix = bisect_right(B, amax)
l = [amax] + B[ix:]
l = list(reversed(l))

if sum(l) > H:
    cnt = 0
    for i in range(len(l)):
        cnt += l[i]
        if cnt >= H:
            print(i + 1)
            exit()
else:
    cnt = len(l)
    amari = H - sum(l)
    cnt += ceil(amari / amax)
    print(cnt)

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

ans = 0
attack = []

for a, b in ab:
    attack += [[a, 0]]
    attack += [[b, 1]]

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

for a, i in attack:
    if i == 1:
        H -= a
        ans += 1
        if H <= 0:
            break
    else:
        cnt = (H-1)//a + 1
        ans += cnt
        break

print(ans)

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

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

B.sort(reverse=True)

res = 0
for b in B:
    if b > Amax:
        res += 1
        if H <= b:
            print(res)
            exit()
        H -= b
    else:
        break

print(res + (H // Amax + int(H % Amax != 0)))

Solution (Python):
import math
n,h = map(int,input().split())
al = []
bl = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    al += [a]
    bl += [b]
am = max(al)
bl.sort(reverse=1)
for i in bl:
    if i>am:
        ans += 1
        h -= i
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += math.ceil(h/am)
print(ans)

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

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

answer = 0
hp = H
attack_cnt = 0

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

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

print(attack_cnt)

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

hq = []
nmax = 0
for i in range(n):
    a, b = map(int,input().split())
    nmax = max(nmax, a)
    heapq.heappush(hq, -b)
heapq.heappush(hq, -nmax)

ans = 0
while h > 0:
    d = -heapq.heappop(hq)
    if d == nmax:
        ans+=max(0, (h+nmax-1)//nmax)
        break
    else:
        h -= d
        ans+=1
print(ans)

Solution (Python):
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)

N,H = I()
A = []
B = []
for i in range(N):
    a,b = I()
    A.append(a)
    B.append(b)
B.sort(reverse=True)
huru = max(A)
cnt = 0
for i in range(N):
    if B[i] < huru:
        break
    H -= B[i]
    cnt += 1
    if H <= 0:
        print(cnt)
        exit()
print(cnt+math.ceil(H/huru))

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)
Max = A[0]
cnt = 0
while H > 0 and cnt < N:
    b = B[cnt]
    if b <= Max:
        break
    H -= b
    cnt += 1
while H > 0:
    H -= Max
    cnt += 1
print(cnt)

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

B = sorted([b for b in B if b>A], reverse=True)
from itertools import accumulate
B = list(accumulate(B))
total_throw_damage = (B[-1] if len(B)>0 else 0)

HP_after_throw = H - total_throw_damage
if HP_after_throw <= 0:
    for i,b in enumerate(B,1):
        if H<=b:
            print(i)
            exit()
    raise AssertionError('error')
else:
    q,r = divmod(HP_after_throw, A)
    print(len(B)+q+min(1, r))

Solution (Python):
import math
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)
    r = 0
    c = 0
    while r < N and A[0] < B[r]:
        c += B[r]
        r += 1
        if c >= H:
            return r
    return int(r + math.ceil((H-c)/A[0]))
print(main())

Solution (Python):
import bisect

N, H=map(int, input().split())
a=[0]*N
b=[0]*N
for i in range(N):
  a[i], b[i]=map(int, input().split())
  
a=max(a)
b.sort()
tmp=bisect.bisect_right(b, a)
if tmp==N:
  print((H-1)//a+1)
  exit()

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

Solution (Python):
import math
n,h=map(int,input().split())
m=0
b=[]
for _ in range(n):
    A,B=map(int,input().split())
    if A>m: m=A
    b.append(B)
b.sort()
j=n-1
ans=0
while True:
    if j<0 or b[j]<=m:
        ans+=math.ceil(h/m)
        break
    h-=b[j]
    j-=1
    ans+=1
    if h<=0: break
print(ans)

Solution (Python):
n,h=map(int,input().split())
a=[0]*n
b=[0]*n
for i in range(n):
    a[i],b[i]=map(int,input().split())
a_max=max(a)
b.sort()
ans=0
for bi in b[::-1]:
    if bi>a_max and h>0:
        h-=bi
        ans+=1
    else:
        break
if h>0:
    ans+=-(-h//a_max)
print(ans)

Solution (Python):
def get_ints():
  return list(map(int, input().split()))

n, h = get_ints()
maxHit = 0
throw = []
for i in range(n):
  x, y = get_ints()
  maxHit = max(maxHit, x)
  throw.append(y)

throw.sort()
throw.reverse()
ans = 0
for d in throw:
  if h <= 0:
    print(ans)
    exit(0)
  if d <= maxHit:
    break
  h -= d
  ans += 1

print(ans + (h + maxHit - 1) // maxHit)

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right,bisect_left
from itertools import accumulate

def 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.sort()
    b.sort()
    i = bisect_left(b,a[N-1])
    c = list(accumulate(b[i:][::-1]))
    
    M = len(c)
    count = bisect_left(c,H)
    if count < M:
        print(count+1)
    else:
        print(count + (H-c[M-1] + a[N-1]-1)//a[N-1])

if __name__ == "__main__":
    main()

Solution (Python):
n,h=map(int,input().split())
a,b=[],[]
for _ in range(n):
    A,B=map(int,input().split())
    a+=[A]
    b+=[B]
c=max(a)
b.sort()
ans=0
for i in b[::-1]:
    if i>c and h>0:
        h-=i
        ans+=1
    else:
        break
print(ans-(-h//c)*(h>0))

Solution (Python):
import sys
input = sys.stdin.readline
n, h = map(int, input().split())
ab = []
for i in range(n):
  a, b = map(int, input().split())
  ab.append((-a, b, i))
  
ab.sort()
index = ab[0][2]
ai = -ab[0][0]
bi = ab[0][1]

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

cnt = 0

for a, b, i in ab2:
    if i == index:
        continue
    if b < ai:
        break
    if h <= bi:
        print(cnt+1)
        sys.exit()
    h -= b
    cnt += 1
    if h <= 0:
        print(cnt)
        sys.exit()


print(cnt + 1 +  max(0, h - bi + ai - 1) // ai)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, h = map(int, readline().split())
    a = [0] * n
    b = [0] * n

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

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

    ans = 0

    for x in b:
        if x >= a_max:
            rem -= x
            ans += 1
            if rem <= 0:
                break
        else:
            break
    if rem > 0:
        ans += (rem + a_max - 1) // a_max
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
import math

n,h = map(int, input().split())
al = []
bl = []
for _ in range(n):
    a,b = map(int, input().split())
    al.append((a,'swing'))
    bl.append((b,'throw'))

abl = al + bl
abl.sort(reverse=True)

remain_h = h
ans = 0
for v in abl:
    damage, command = v
    if command == 'swing':
        ans += math.ceil(remain_h/damage)
        break
    else:
        ans += 1
        remain_h -= damage
        if remain_h <= 0:
            break

print(ans)

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

ka = []
th = []

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

ths = sorted(th)
thr = sorted(th, reverse=True)

import itertools
sumthr = list(itertools.accumulate(thr))

mk = max(ka)

if mk >= max(th):
    print(-(-h//mk))
    exit()


import bisect
t = bisect.bisect(ths,mk)

res = 0
for i in range(n-t):
    if h > sumthr[i]:
        pass
    else:
        print(i+1)
        exit()

    if i ==n-1:
        print(-((sumthr[-1]-h)//mk)+i+1)
        exit()

print(-((sumthr[i]-h)//mk)+i+1)

Solution (Python):
n, hp = map(int, input().split())
mat = [list(map(int, input().split())) for _ in range(n)]
mat.sort(key=lambda x:-x[1])
sword = max(mat, key=lambda x:x[0])[0]
s, t = mat[0]
idx = 0
ans = 0
for _, throw in mat:
    if throw > sword:
        hp -= throw
        ans += 1
        if hp <= 0:
            print(ans)
            exit()
    else:
        break
d, m = divmod(hp, sword)
ans += d + min(1, m)
print(ans)