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(" "))
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
while(b[c] > a[0]):
    H -= b[c]
    c += 1
    if c == len(b):break
    if H <= 0:break
if H > 0:
    if (H % a[0] != 0):c += 1
    c += H // a[0]
print(c)

Solution (Python):
from sys import stdin
from collections import deque
d = deque()
N,H= list(map(int,stdin.readline().strip().split()))
damage=[list(map(int,input().split())) for x in range(N)]
a=[l[0] for l in damage]
b=[l[1] for l in damage]
b.sort(reverse=True)
a.sort(reverse=True)
max_a=a[0]
oppai=0
sum_=0
count=0
for num in b:
    if max_a<num:
        sum_ += num
        count += 1
        oppai+=num
        if sum_>=H:
            print(count)
            exit()
    else:break

H-=oppai
count+=H//max_a
if H%max_a==0:
    print(count)
    exit()
else:
    print(count+1)
    exit()

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

attack=max(AB)[0]
AB=sorted(AB, reverse=True, key=lambda x:x[1])
cnt=0
for i,j in AB:
    if j>=attack:
        h -=j
        cnt +=1
    if h<=0:print(cnt);exit()

print(cnt+h//attack if h%attack==0 else cnt+h//attack+1)

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

a = []
b = []
for i, j in ab:
    a.append(i)
    b.append(-j)
heapify(b)
max_a = max(a)

cnt = 0
while h > 0:
    temp = heappop(b) * (-1) if b else 0
    if temp > max_a:
        h -= temp
        cnt += 1
    else:
        temp = (h + max_a - 1)/max_a
        h -= max_a * int(temp)
        cnt += int(temp)

print(cnt)

Solution (Python):
n, h = map(int, input().split())
amax = 0
bs = []
for i in range(n):
  a, b = map(int, input().split())
  amax = max(amax, a)
  bs.append(b)
bs = sorted([i for i in bs if i >= amax], reverse=True)
ans = 0
for i in bs:
  h -= i
  ans += 1
  if h <= 0:
    break
else:
  ans += (h + amax - 1) // amax
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)

B.sort(reverse=True)
amax=max(A)
ans=0
l=0
for b in B:
  if l>=H:
    print(ans);exit()
  if b>amax:
    ans+=1
    l+=b
  else:
    break
ans+=(H-l)//amax+min((H-l)%amax,1)
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
N, H = map(int, readline().split())
B = [0] * N
ma = 0
for i in range(N):
     a, b = map(int, readline().split())
     if ma < a:
        ma = a
     B[i] = b
B.sort(reverse=True)
ans = 0
for b in  B:
    if ma < b:
        ans += 1
        H -= b
    if H <= 0:
        print(ans)
        exit()
ans -= -H//ma
print(ans)

Solution (Python):
n, h = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab_b = sorted(ab, key=lambda x:x[1])[::-1]
ma = max(ab[i][0] for i in range(n))
cnt = 0
for i in range(n):
    if ab_b[i][1] <= ma:
        break
    h -= ab_b[i][1]
    cnt += 1
    if h <= 0:
        print(cnt)
        exit()
print(cnt + (-h//ma)*-1)

Solution (Python):
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)
b=sorted(b,reverse=True)
amax=max(a)
newb=[0]
for i in range(n):
    if b[i]>amax:
        newb.append(b[i])
from itertools import accumulate
newb=list(accumulate(newb))
ans=0
for i in range(len(newb)):
    if newb[i]>=h:
        ans=i
        break
if ans==0:
    ans+=len(newb)-1
    ans+=(h-max(newb))//amax
    if (h-max(newb))%amax>0:
        ans+=1
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())
ab=sorted(a+b)[::-1]
ans=0
for i in ab[:ab.index(max(a))]:
  h-=i
  ans+=1
  if h<=0:
    print(ans)
    exit()
ans+=(h+max(a)-1)//max(a)
print(ans)

Solution (Python):
import bisect













import sys

sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():
    N, H = map(int, input().split())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())
    B.sort()
    ma = max(A)
    ind = bisect.bisect_right(B, ma)

    cnt = 0
    i = N - 1
    while H > 0:
        if i +1> ind:
            H -= B[i]
            cnt += 1
            i -= 1
        else:
            cnt += -(-H // ma)
            break

    print(cnt)


resolve()

Solution (Python):
import sys

IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

INIT_VAL = 0
MD2 = lambda d1,d2: [[INIT_VAL]*d2 for _ in range(d1)]
MD3 = lambda d1,d2,d3: [MD2(d2,d3) for _ in range(d1)]

DIVC = lambda x,y: -(-x//y)
DIVF = lambda x,y: x//y

def main():
    n, h = MII()
    attacks = [MII() for _ in range(n)]
    max_a = sorted(attacks)[-1][0]
    bb = [a[1] for a in attacks if a[1] > max_a]
    bb.sort(reverse=True)
    total_b = sum(bb)
    if total_b >= h:
        cnt = 0
        for i, b in enumerate(bb):
            cnt += b
            if cnt >= h:
                print(i+1)
                return None
    d = h - total_b
    cnt = DIVC(d, max_a)
    print(cnt + len(bb))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


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)

    B =sorted(B, reverse=True)
    max_a = max(A)
    res = 0
    for i in range(n):
        if B[i] > max_a:
            h -= B[i]
            res += 1
        if h <= 0:
            break

    res += max(0, math.ceil(h / max_a))
    print(res)


if __name__ == '__main__':
    resolve()

Solution (Python):

import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,H=map(int,input().split())
    a,b=[0]*N,[0]*N
    for i in range(N):
        a[i],b[i]=map(int,input().split())
    b.sort(reverse=1)
    a.sort(reverse=1)
    ans=0
    for i in range(N):
        if b[i]<a[0]:
            break
        ans+=1
        H-=b[i]
        if H<=0:
            print(ans)
            exit()
    print(ans-(-H//a[0]))

if __name__ == '__main__':
    main()

Solution (Python):
N,H=list(map(int,input().split()))
a=[0]*N
b=[0]*N

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

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

res=10**10
csum=0
for i in range(N+1):
    cnt=i
    ch=H
    csum+=b[i-1] if i>0 else 0
    ch-=csum

    if ch>0:
        cnt+=-(-ch//amax)

    res=min(res,cnt)

print(res)

Solution (Python):
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.sort()
b.sort()
from bisect import bisect_left
end = bisect_left(b, max(a))

i = N - 1
cnt = 0
while H > 0 and end <= i:
    
    H -= b[i]
    cnt += 1
    i -= 1
if H <= 0:
    print(cnt)
    quit()
import math
print(math.ceil(H / max(a)) + cnt)

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

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

throw_list=[]
for b in blist:
  if b>max_swing:
    throw_list.append(b)
throw_list.sort(reverse=True)


answer=0
for t in throw_list:
  answer+=1
  H-=t
  if H<=0:
    print(answer)
    sys.exit(0)
    

print(answer+(H-1)//max_swing+1)

Solution (Python):
import copy
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
for i in range(n):
    ab[i].append(i)
ab1=copy.copy(ab)
if n==1 and (h-ab[0][1])%ab[0][0]==0:
    print((h-ab[0][1])//ab[0][0]+1)
elif n==1 and (h-ab[0][1])%ab[0][0]!=0:
    print((h-ab[0][1])//ab[0][0]+2)
else:
    ab1.sort()
    ma=ab1[-1][0]
    l=[]
    for i in range(n):
        if ab1[i][0]==ma:l.append(ab1[i])
    l.sort()
    ak=ab.pop(l[0][2])
    ab.sort(key=lambda x:x[1])
    ac=0
    for i in range(1,n):
        if ak[1]>=h:
            h-=ak[1]
            ac+=1
        elif ak[0]>ab[-i][1]:
            h-=ak[0]
            ac+=1
        else:
            h-=ab[-i][1]
            ac+=1
        if h<=0:
            print(ac)
            exit()
    if h<=ak[1]:
        print(ac+1)
    else:
        if (h-ak[1])%ak[0]==0:
            ac+=((h-ak[1])//ak[0])+1
        else:ac+=((h-ak[1])//ak[0])+2
        print(ac)

Solution (Python):
import sys
import math  
import bisect  
import queue  


def input():
    return sys.stdin.readline().rstrip()


if __name__ == '__main__':
    N, H = map(int, input().split())
    A = [0 for _ in range(N)]
    B = [0 for _ in range(N)]
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b

    max_a = max(A)
    weapon = []
    for b in B:
        if b <= max_a:
            continue
        else:
            weapon.append(b)

    weapon.sort(reverse=True)
    cnt = 0
    for w in weapon:
        cnt += 1
        H -= w
        if H <= 0:
            print(cnt)
            exit(0)

    cnt += math.ceil(H / max_a)
    print(cnt)

Solution (Python):
from math import ceil
N,H=list(map(int,input().split()))
a_max=0
b_list=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    a_max = max(a_max,a)
    b_list.append(b)
b_list = sorted(b_list,reverse=True)

ans=ceil(H/a_max)
bcount=0
for b in b_list:
    bcount+=1
    H=max(0,H-b)
    ans=min(ans,bcount+ceil(H/a_max))

print(ans)

Solution (Python):


import io
import sys
import math

n,h,*l=map(int,open(0).read().split())

array=max(l[::2])

c=0;f=1

for b in sorted(l[1::2])[::-1]:
	if b>array:
		h-=b
		c+=1
		if h<1:
			f=0
			break
print(c+(~-h//array+1)*f)

Solution (Python):
from math import ceil
N,H=list(map(int,input().split()))
a_max=0
b_list=[]
for _ in range(N):
    a,b=list(map(int,input().split()))
    a_max = max(a_max,a)
    b_list.append(b)
b_list = sorted(b_list,reverse=True)

ans=ceil(H/a_max)
bcount=0
for b in b_list:
    bcount+=1
    H=max(0,H-b)
    ans=min(ans,bcount+ceil(H/a_max))

print(ans)

Solution (Python):
n,h = (int(x) for x in input().split())
seq = []
maxa = 0
sumb = 0
cnt = 0
for i in range(n):
    a, b = [int(x) for x in input().split()]
    if a > maxa:
        maxa = a
        cnt = 1
    elif a == maxa:
        cnt += 1
    seq.append((a,b))
    sumb += b
s = sorted(seq, key=lambda x: x[1], reverse=True)
i = 0
ans = 0
while h > 0:
    a,b = s[i]
    h -= b
    ans += 1
    if a == maxa and cnt > 1:
        cnt -= 1
    elif a == maxa:
        i += 1
        while i < n:
            a,b = s[i]
            if b > maxa:
                ans += 1
                h -= b
                i += 1
            else:
                break

        ans += (h + maxa - 1) // maxa
        break
    i += 1
print(ans)

Solution (Python):
import math
N,M=(int(x) for x in input().split())
a=[0]*(N)
b=[0]*(N)
c=0
v=0
for i in range(N):
    A,B=(int(x) for x in input().split())
    a[i]=A
    b[i]=B

v = max(a)

b.sort(reverse=True)


i=0
for i in b:
    if i>=v:
        c+=1
        M-=i
    else:break
    if M <= 0:
        break
if M>0:
    c+=math.ceil(M/v)
print(c)

Solution (Python):
import sys

n,h = map(int,input().split())
a,b = [0]*n,[0]*n
for i in range(n):
    a[i],b[i] = map(int,input().split())
    
c = sorted(b,reverse = True)
maa = max(a)

ans = 0
for i in range(n):
    if c[i] > maa:
        ans += 1
        h -= c[i]
    else:
        break
        
    if h <= 0:
        print(ans)
        sys.exit()
        
ans += (h-1) // maa + 1
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline


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

    a.sort()
    b.sort()

    atk = 0
    ans = 0
    for i in reversed(range(N)):
        if b[i] < a[-1]:
            break
        else:
            atk += b[i]
            ans += 1
            if atk >= H:
                break

    if atk < H:
        rem = H - atk
        q, r = divmod(rem, a[-1])
        ans += q
        ans += 1 if r > 0 else 0

    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
from math import ceil
n, h = map(int, input().split())
a_nums = []
b_nums = []
for _ in range(n):
    a, b = map(int, input().split())
    a_nums.append(a)
    b_nums.append(b)
a_nums = sorted(a_nums)
b_nums = sorted(b_nums)
cnt = 0
while h > 0:
    a = a_nums.pop()
    if b_nums:
        b = b_nums.pop()
        if b >= a:
            h -= b
        else:
            h -= a
        a_nums.append(a)
        cnt += 1
    else:
        cnt += ceil(h / a)
        break
print(cnt)

Solution (Python):
n, h = map(int, input().split())
sord = [0]*n
for i in range(n):
  sord[i] = [int(x) for x in input().split()]
sord.sort(reverse=True)

throw = [0]*(n-1)
for i in range(1, n):
  throw[i-1] = sord[i][1]
throw.sort(reverse=True)

a = sord[0][0]
b = sord[0][1]

ans = 0
for i in range(n-1):
  if h <= b:
    ans += 1
    h -= b
    break
  if a >= throw[i]:
    break
  if h <= throw[i]:
    h -= throw[i]
    ans += 1
    break
  h -= throw[i]
  ans += 1

if h > 0:
  ans += 1
  h -= b
  if h>0:
    ans += (h-1)//a+1
print(ans)

Solution (Python):
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)
MAX = max(A)
B.sort(reverse = True)
ans = 0
for i in B:
    if i > MAX:
        ans += 1
        H -= i
    else:
        break
    if H <= 0:
        break
if H > 0:
    ans += math.ceil(H / MAX)
print(ans)

Solution (Python):
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)]
a_featured = ab[:]
b_featured = ab[:]
a_featured = sorted(a_featured, key=lambda x: [x[0], x[1]], reverse=True)
b_featured = sorted(b_featured, key=lambda x: [x[1], x[0]], reverse=True)
a_max = a_featured[0]
ans = 0
for i in range(N):
    if b_featured[i][1] >= a_max[0]:
        H -= b_featured[i][1]
        ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H-1)//a_max[0] + 1)

Solution (Python):
import math
n,h=map(int,input().split())
a_max=0
b_=[]
for i in range(n):
    a,b=map(int,input().split())
    b_.append(b)
    if a_max<a:
        a_max=a
ans=0
b_=sorted(b_,reverse=True)
for i in range(n):
    if a_max<b_[i]:
        ans+=1
        h-=b_[i]
        if h<=0:
            h=0
            break
print(ans+math.ceil(h/a_max))

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

max_a = max(a_list)
b_list = [ i for i in b_list if i > max_a ]
b_list.sort(reverse = True)

total = 0
count = 0
for d in b_list:
    total += d
    count += 1
    if total >= H:
        break

if total < H:
    x = math.ceil((H - total) / float(max_a))
    count += x

print(count)

Solution (Python):
n,h=map(int,input().split())
ab=[[int(i) for i in input().split()] for _ in range(n)]
maxa=max(map(lambda x:x[0], ab))
ab.sort(key=lambda x:x[1],reverse=True)
ans=0
for a,b in ab:
  if b>maxa:
    h-=b
    ans+=1
  if h<=0:
    print(ans)
    exit(0)
print(ans+(h-1)//maxa+1)

Solution (Python):
n,h,*ab = map(int,open(0).read().split())
a_max = max(ab[::2])
b_sort = sorted(ab[1::2],reverse = True)

ans = 0
i = 0
while h>0:
    if i<n and b_sort[i] > a_max:
        h -= b_sort[i]
        i += 1
        ans += 1
    else:
        ans += -(-h//a_max)
        h = 0
print(ans)

Solution (Python):
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a_max=0
b=[]
ans=0
kaisuu=0
for i in range(n):
  if a_max<ab[i][0]:
    a_max=ab[i][0]
for i in range(n):
  b.append(ab[i][1])
b.sort(reverse=True)
i=0
while True:
  if len(b)>i and a_max<b[i]:
    h-=b[i]
    kaisuu+=1
  else:
    if h%a_max==0:
      kaisuu+=(h//a_max)
    else:
      kaisuu+=((h//a_max)+1)
    break
  if h<=0:
    break
  i+=1
print(kaisuu)

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

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

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

maxA = max(A)
maxAcount = N-1
for i in range(N-1):
    if A[i] != A[i+1]:
        maxAcount = i
        break

i = 0
ans = 0
while H > 0:
    if i == N:
        ans += math.ceil(H/maxA[0])
        H = 0
    else:
        b, k = B[i]
        if b > maxA[0]:
            H -= b
            i += 1
            ans += 1
        else:
            ans += math.ceil(H/maxA[0])
            H = 0

print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n,h = m()
po = []
for i in range(n):
    a,b = m()
    po.append([a,b])

po.sort(reverse = True)

on = po[0]

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

co = 0

for i in range(n):
    if h <= 0:
        break
    if on[0] <= po[i][1]:
        co += 1
        h -= po[i][1]
    else:
        break
if h <= 0:
    print(co)
else:
    print(co + (-(-h//on[0])))

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)
BB = [B[i] for i in range(n) if B[i] > max_A]
BB.sort(reverse=True)

cnt = 0
for i in range(len(BB)):
	if h <= 0: 
		print(cnt)
		exit()
	h -= BB[i]
	cnt += 1


if h % max_A == 0:
	cnt += h // max_A
else:
	cnt += h // max_A + 1

print(cnt)

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

A = []
B = []

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

A = sorted(A)
B = sorted(B)

t = 0
total = 0
max_a = max(A)

for i in B:
    if i >= max_a:
        t += 1
        total += i

if total <= h:
    h = h - total

    if h % max_a == 0:
        print(h // max_a + t)
    else:
        print(h//max_a + t + 1)
else:
    ans = 0
    for j in B[::-1]:
        if h > 0:
            h -= j
            ans += 1
        else:
            break
    print(ans)

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

b_sum = 0
a_max = 0

a_li = []
b_li = []

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


a_li.sort(reverse=True)
b_li.sort(reverse=True)

pt = 0
a_num = 0
b_num = 0
ans = 0

for i in range(2*n):
    if b_num >= n:
        ans += (h-pt+a_li[a_num]-1) // a_li[a_num]
        print(ans)
        exit()
    if a_li[a_num] < b_li[b_num]:
        pt += b_li[b_num]
        b_num += 1
        ans += 1
        if pt >= h:
            print(ans)
            exit()
    else:
        ans += (h-pt+a_li[a_num]-1) // a_li[a_num]
        print(ans)
        exit()

Solution (Python):
N, H = map(int, input().split())
sword = [tuple(map(int, input().split()))
         for _ in range(N)]
sword.sort(key=lambda x: (x[1], x[0]), reverse=True)

base = 0
a0, b0 = sword[base]
for i in range(1, N):
    ai, bi = sword[i]
    if ai > a0 or (ai == a0 and bi < b0):
        base = i
        a0, b0 = ai, bi


def solve():
    cnt = 0
    h = H
    bi = 1 if base == 0 else 0
    while h > 0:
        if h < b0:
            cnt += 1
            break
        if bi >= len(sword) or a0 >= sword[bi][1]:
            if a0 < b0:
                h -= b0
                cnt += 1
            if h % a0 == 0:
                cnt += h // a0
                break
            else:
                cnt += h // a0 + 1
                break
        h -= sword[bi][1]
        bi += 1
        if bi == base:
            bi += 1
        cnt += 1
    return cnt


print(solve())

Solution (Python):
import bisect

N, H = map(int, input().split())
A = []
B = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ma = max(A)
B.sort()
idx = bisect.bisect_left(B, ma)
ans = 0
point = 0
for i in range(N - 1, idx - 1, -1):
    ans += 1
    point += B[i]
    if point >= H:
        print(ans)
        break
else:
    diff = H - point
    ans += (diff + ma - 1) // ma
    print(ans)

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

lst = []
for _ in range(N):
    a, b = map(int, input().split())
    lst.append((a, 0))
    lst.append((b, 1))
lst.sort(reverse=True)

ans = 0
ceil = lambda a, b: (a + b - 1) // b

for p, q in lst:
    if q == 1:
        H -= p
        ans += 1
        if H <= 0:
            break
    else:
        ans += ceil(H, p)
        break
print(ans)

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

Solution (Python):
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)
Ma = max(a)
b.sort(reverse = True)
count = 0
for i in range(n):
    if b[i] > Ma:
        count += 1
        h -= b[i]
        if h <= 0:
            print(count)
            exit()
    else:
        break
count += -(-h//Ma)
print(count)

Solution (Python):
from bisect import bisect_left
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(A)
B = sorted(B)

count,damage = 0,0
b = bisect_left(B,A)

for i in range(len(B)-1,b-1,-1):
  damage += B[i]
  count += 1
  if damage >= H:
    print(count)
    exit()

count,damage = 0,0
damage = sum(B[b:])
count += len(B[b:])
count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)

Solution (Python):







def main():
    N, H = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[1], reverse=True)

    a_max = max([a for a, _ in ab])

    throw_dmg = 0
    n_throw = 0
    for _, b in ab:
        if b > a_max:
            throw_dmg += b
            n_throw += 1
            if throw_dmg >= H:
                return n_throw
        else:
            break

    rest = H - throw_dmg

    if rest % a_max == 0:
        return rest // a_max + n_throw
    else:
        return rest // a_max + 1 + n_throw


print(main())

Solution (Python):







def main2():
    N, H = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[1], reverse=True)

    a_maxs = [None] * N
    a_max = ab[-1][1]
    for i in range(N-1, -1, -1):
        a, _ = ab[i]
        if a > a_max:
            a_max = a
        a_maxs[i] = a_max
    
    
    

    counts = [None] * (N+1)
    throw_dmg = 0
    for k in range(N+1):  
        if k > 0:
            throw_dmg += ab[k-1][1]

        rest = H - throw_dmg

        if k == N:
            counts[k] = 10**10 if rest > 0 else k
            continue
        
        last_throw_dmg = ab[k][1]  

        

        if rest <= 0:
            counts[k] = k
        
        
        elif rest % a_maxs[k] == 0:
            counts[k] = k + rest // a_maxs[k]
        else:
            counts[k] = k + rest // a_maxs[k] + 1
    print(counts)
    return min(counts)


def main():
    N, H = map(int, input().split())
    ab = [None] * N
    for i in range(N):
        ab[i] = list(map(int, input().split()))
    ab = sorted(ab, key=lambda x: x[1], reverse=True)

    a_max = max([a for a, _ in ab])

    throw_dmg = 0
    n_throw = 0
    for _, b in ab:
        if b > a_max:
            throw_dmg += b
            n_throw += 1
            if throw_dmg >= H:
                return n_throw
        else:
            break

    rest = H - throw_dmg

    if rest % a_max == 0:
        return rest // a_max + n_throw
    else:
        return rest // a_max + 1 + n_throw


print(main())

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,h = map(int, input().split())
    a, b = [], []
    for _ in range(n):
        x, y = map(int, input().split())
        a.append(x)
        b.append(y)

    c = max(a)
    res = 0
    b.sort(reverse=True)
    for i in b:
        if i > c:
            h -= i
            res += 1
        if h <= 0:
            print(res)
            exit()
    print(res+(h+c-1)//c)

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n,h = map(int, input().split())
    a, b = [], []
    for _ in range(n):
        x, y = map(int, input().split())
        a.append(x)
        b.append(y)

    c = max(a)
    res = 0
    b.sort(reverse=True)
    for i in b:
        if i > c:
            h -= i
            res += 1
        if h <= 0:
            print(res)
            exit()
    if h%c == 0:
        print(res+h//c)
    else:
        print(res+h//c+1)

if __name__ == '__main__':
    main()

Solution (Python):
N,H = [int(x) for x in input().split()]
from collections import deque
import math
c = []
d = []
for i in range(N):
  e,f = [int(x) for x in input().split()]
  c.append(e)
  d.append(f)
c.sort()
d.sort()
b = deque(d)
count = 0
while b:
  x = b.pop()
  if x > c[-1]:
    H -= x
    count += 1
    if H <= 0:
      print(count)
      exit()
count += math.ceil(H/c[-1])
print(count)

Solution (Python):
import math
N,H=map(int,input().split())
sword=[list(map(int,input().split())) for _ in range(N)]
throw=0
smash=0
cnt=0
sword.sort(key=lambda x:x[0],reverse=True)
smashmax=sword[0][0]
sword.sort(key=lambda x:x[1],reverse=True)
for i in range(N):
    if (smashmax<=sword[i][1])and(throw<H):
        throw=throw+sword[i][1]
        cnt=cnt+1
if throw>=H:
    print(cnt)
else:
    print(cnt+math.ceil((H-throw)/smashmax))

Solution (Python):



import math


N,H = list(map(int, input().split()))
a,b = [],[]
for n in range(N):
    a_n,b_n = list(map(int, input().split()))
    a.append(a_n)
    b.append(b_n)





max_a = max(a)
sorted_b = reversed(sorted(b))
min_count = 0
for b_n in sorted_b:
    if (b_n < max_a) or (H <= 0):
        break
    H -= b_n
    min_count += 1

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


print(min_count)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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())
max_a = max(a)
check = len([i for i in b if i > max_a])
b.sort(reverse=True)
for i in range(check):
    h -= b[i]
    if h <= 0:
        print(i + 1)
        exit()
if h % max_a == 0:
    print(h // max_a + check)
else:
    print(h // max_a + check + 1)

Solution (Python):

import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    ma = max(a)
    b.sort(reverse=True)
    i = 0
    for i in range(N):
        if b[i] <= ma:
            i -= 1
            break
        H -= b[i]
        if H <= 0:
            print(i + 1)
            return
    print(i + 1 + -(-H // ma))


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


if __name__ == '__main__':
    main()

Solution (Python):
n, h = map(int, input().split())
a = []
b = []
for _ in range(n):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)
a = max(a)
b = [i for i in b if i > a]
b.sort(reverse=True)
lb = len(b)

for i in range(lb):
    h -= b[i]
    if h <= 0:
        print(i+1)
        exit()
if h % a == 0:
    print(h//a + lb)
else:
    print(h//a + lb + 1)