Problem:
 Score : 400 points    Problem Statement You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1 , Katana 2 , … , Katana N , and can perform the following two kinds of attacks in any order:   Wield one of the katana you have. When you wield Katana i  (1 ≤ i ≤ N) , the monster receives a_i points of damage. The same katana can be wielded any number of times.  Throw one of the katana you have. When you throw Katana i  (1 ≤ i ≤ N) at the monster, it receives b_i points of damage, and you lose the katana. That is, you can no longer wield or throw that katana.   The monster will vanish when the total damage it has received is H points or more. At least how many attacks do you need in order to vanish it in total?      Constraints  1 ≤ N ≤ 10^5  1 ≤ H ≤ 10^9  1 ≤ a_i ≤ b_i ≤ 10^9  All input values are integers.         Input Input is given from Standard Input in the following format:  N  H  a_1  b_1  :  a_N  b_N       Output Print the minimum total number of attacks required to vanish the monster.        Sample Input 1 1 10
3 5      Sample Output 1 3  You have one katana. Wielding it deals 3 points of damage, and throwing it deals 5 points of damage. By wielding it twice and then throwing it, you will deal 3 + 3 + 5 = 11 points of damage in a total of three attacks, vanishing the monster.       Sample Input 2 2 10
3 5
2 6      Sample Output 2 2  In addition to the katana above, you also have another katana. Wielding it deals 2 points of damage, and throwing it deals 6 points of damage. By throwing both katana, you will deal 5 + 6 = 11 points of damage in two attacks, vanishing the monster.       Sample Input 3 4 1000000000
1 1
1 10000000
1 30000000
1 99999999      Sample Output 3 860000004       Sample Input 4 5 500
35 44
28 83
46 62
31 79
40 43      Sample Output 4 9

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7
dd=[(-1,0),(0,1),(1,0),(0,-1)]
ddn=[(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return input()

def main():
  n,h=LI()
  l=[]

  for _ in range(n):
    a,b=LI()
    l.append([a,-1])
    l.append([b,1])

  l=sorted(l,key=lambda x:x[0],reverse=True)
  

  ans=0
  for i,x in enumerate(l):
    if x[1]==1:
      ans+=1
      h-=x[0]
    else:
      ans+=-(-h//x[0])
      return ans

    if h<=0:
      return ans

  return ans


print(main())

Solution (Python):


from math import ceil

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

a_max = max(a_li)
b_li.append(a_max)
b_li.sort()

cnt = 0
while h > 0:
    b_max = b_li.pop()
    if b_max == a_max:
        cnt += ceil(h / a_max)
        break
    else:
        h -= b_max
        cnt += 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)
maxa = max(a)
b.sort(reverse=True)
ans = 0
tmp = 0
for i in range(N):
    if b[i] <= maxa:
        break
    ans += 1
    tmp += b[i]
    if tmp >= H:
        break
if tmp < H:
    ans += -(-(H-tmp) // maxa)

print(ans)

Solution (Python):
n, h = map(int, input().split())
k = [None] * (n*2)

from math import ceil

for i in range(0, n*2, 2):
    a, b = map(int, input().split())
    k[i] = (a, True)
    k[i+1] = (b, False)

k.sort(reverse=True)
cnt = 0

for i in range(n*2):
    if k[i][1]:
        print(i + ceil((h - cnt) / k[i][0]))
        break
    cnt += k[i][0]
    if cnt >= h: 
        print(i+1)
        break

Solution (Python):

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


if __name__ == "__main__":
    main()

Solution (Python):
def main():

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

    print(count)

if __name__ == "__main__":
    main()

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

Kft = sorted([b for b in Kft if b > maxa])
ans = 0
while H > 0 and len(Kft) > 0:
    H -= Kft.pop(-1)
    ans += 1
if H > 0:
    if H % maxa == 0:
        ans += H // maxa
    else:
        ans += H // maxa + 1
print(ans)

Solution (Python):
N,H = [int(x) for x in input().split()]
a = [[int(x) for x in input().split()] for _ in range(N)]
a = sorted(a,reverse=True,key= lambda x : x[1])
ma = max(a,key = lambda x:x[0])[0]
cnt = 0
su = 0
for i in range(N):
  if a[i][1]>=ma:
    if su<H:
      cnt+=1
      su += a[i][1]
    else:
      print(cnt)
      exit()
H -= su
if H<=0:
  print(cnt)
  exit()
cnt+= (H+ma-1)//ma
print(cnt)

Solution (Python):
n,h = (int(i) for i in input().split())
a = []
b = []
cnt = 0
for i in range(n):
  x,y = (int(i) for i in input().split())
  a.append(x)
  b.append(y)
max = max(a)
b.sort()
for i in b[::-1]:
  if i >= max:
    h -= i
    cnt += 1
 
  if h <= 0:
    print(cnt)
    exit()
import math
cnt += int(math.ceil(h / max))
print(cnt)

Solution (Python):
import math
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(reverse=True)
    b.sort(reverse=True)

    m = N
    for i in range(N):
        if b[i] > a[0]:
            continue
        else:
            m = i
            break
    
    for i in range(m):
        H -= b[i]
        if H <= 0:
            print(i+1)
            exit()
    
    print(math.ceil(H / a[0]) + m)


if __name__ == "__main__":
    main()

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


def main():
    N, H = map(int, input().split())
    a_max = 0
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        a_max = max(a, a_max)
        B.append(-b)
    heapq.heapify(B)

    cnt = 0
    while H>0:
        if len(B)==0 or a_max >= B[0]*(-1):
            cnt += math.ceil(H/a_max)
            break
        else:
            cnt += 1
            H += heapq.heappop(B)
    
    print(cnt)

if __name__ == '__main__':
    main()

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


def main():
    N, H = map(int, input().split())
    a_max = 0
    B = []
    for _ in range(N):
        a, b = map(int, input().split())
        a_max = max(a, a_max)
        B.append(-b)
    heapq.heapify(B)

    cnt = 0
    while H>0:
        if len(B)==0 or a_max >= B[0]*(-1):
            cnt += math.ceil(H/a_max)
            break
        else:
            cnt += 1
            H += heapq.heappop(B)
    
    print(cnt)

if __name__ == '__main__':
    main()

Solution (Python):
n, h = map(int, input().split())
ls = [list(map(int, input().split())) for _ in range(n)]
a = max([l[0] for l in ls])
bs = [l[1] for l in ls if l[1] > a]
bs.sort()
res = 0
while h > 0 and len(bs) > 0:
    h -= bs.pop()
    res += 1
if h > 0:
    res += (h + a - 1) // a
print(res)

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

def main():
    N,H = map(int, input().split())
    X = []

    k = 0 
    for _ in range(N):
        a,b = map(int, input().split())
        X.append((a,b))
        k = max(k,a)

    TK = [x for x in X if x[1] > k] 
    TK.sort(key=lambda x: x[1])

    ans = 0
    while H > 0:
        if TK:
            H -= TK.pop()[1]
            ans += 1
        else:
            ans += math.ceil(H/k)
            break
    print(ans)

if __name__ == '__main__':
    main()

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

def main():
    N,H = map(int, input().split())
    X = []
    k = 0 
    for _ in range(N):
        a,b = map(int, input().split())
        X.append((a,b))
        k = max(k,a)

    TK = [] 
    for x in X:
        if x[1] > k:
            TK.append(x)
    TK.sort(key=lambda x: x[1])

    ans = 0
    while H>0:
        if TK:
            H -= TK.pop()[1]
            ans += 1
        else:
            ans += math.ceil(H/k)
            break
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):


import sys
input=sys.stdin.readline

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

que=[]

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

que.sort(key=lambda x: (x[0],x[1]))
a,b=que.pop()
que.sort(key=lambda x: x[1])

cnt=0
def solve(cnt,h):
    while h>0 and que:
        _,bb=que.pop()
        if h<=b:
            break
        if bb>=a:
            h-=bb
            cnt+=1
        else:
            break
    return cnt,h

if que:
    cnt,h=solve(cnt,h)



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

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

katana = [tuple(map(int, input().split())) for _ in range(N)]

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

max_a, sonob = katana.pop(0)




target = H
cnt = 0

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

for i in range(len(katana)):
    if target <= 0:
        print(cnt)
        exit()
    if max_a > katana[i][1]:  
        break
    target -= katana[i][1]
    cnt += 1

target -= sonob
cnt += 1
print(cnt+int(math.ceil(target/max_a)))

Solution (Python):
n,h=map(int,input().split())
ab=[]
for i in range(n):
	x,y=map(int,input().split())
	ab.append([x,y])
x=ab[0][0]
for i in range(n):
	x=max(x,ab[i][0])
ab.sort(key=lambda x:-x[1])
k=n
for i in range(n):
	if x>=ab[i][1]:
		k=i
		break
ans=0
ab.sort(key=lambda x:-x[1])
for i in range(k):
	h-=ab[i][1]
	ans+=1
	if h<=0:
		print(ans)
		exit()
import math
ab.sort(key=lambda x:-x[0])
ans+=math.ceil(h/ab[0][0])
print(ans)

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

max_a = max(P[i][0] for i in range(N))
B = sorted([P[i][1] for i in range(N) if P[i][1] > max_a], reverse=True)

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

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

Solution (Python):

import numpy as np
n,h = map(int,input().split())
A = []
B = []
ans = 0

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

B = np.array(B)
a = max(A)
B = B[B > a]
B = np.sort(B)[::-1]

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

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    
    N,H = map(int,input().split())
    AB = [list(map(int,input().split())) for i in range(N)]
    
    AB = sorted(AB,key=lambda a:a[1])[::-1]
    AB = sorted(AB,key=lambda a:a[0])[::-1]
    master = AB[0]
    throw1 = []
    throw2 = []
    for i in range(1,N):
        if AB[i][1] >= master[1]:
            throw1.append(AB[i][1])
        elif AB[i][1] > master[0]:
            throw2.append(AB[i][1])
    throw1 = sorted(throw1)[::-1]
    throw2 = sorted(throw2)[::-1]
    
    throw1Sum = sum(throw1)
    throw2Sum = sum(throw2)
    tmpH = H
    ans = 0
    
    if throw1Sum < H:
        ans += len(throw1)
        tmpH -= throw1Sum
        if throw2Sum+master[1] < H:
            ans += len(throw2)
            tmpH -= throw2Sum
            ans += max(1, -(-(tmpH-master[1])//master[0])+1)
        else:
            throw2.append(master[1])
            throw2 = sorted(throw2)[::-1]
            i = 0
            while tmpH > 0:
                ans += 1
                tmpH -= throw2[i]
                i +=1
    else:
        i = 0
        while tmpH > 0:
            ans += 1
            tmpH -= throw1[i]
            i += 1
    print(ans)

main()

Solution (Python):
import math
import heapq

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

a,b=0,0
a_max=0
h=[]
heapq.heapify(h)

for i in range(N):
    a,b=map(int,input().split())
    a_max=max(a_max,a)
    heapq.heappush(h,-b) 

ans=0
while H>0:
    if len(h)==0:
        ans+=math.ceil(H/a_max)
        break
    b_max=-heapq.heappop(h)
    if b_max<a_max:
        ans+=math.ceil(H/a_max)
        break
    ans+=1
    H-=b_max

print(ans)

Solution (Python):
import math


def main():
    n, h = map(int, input().split(' '))
    katanas = [list(map(int, input().split(' '))) for _ in range(n)]
    
    count = 0

    a_max = max(map(lambda k: k[0], katanas))
    b_s = list(sorted(map(lambda k: k[1], filter(lambda k: k[1] > a_max, katanas)), reverse=True))
    
    while h > 0:
        if b_s:
            h -= b_s[0]
            del b_s[0]
        else:
            count += math.ceil(h / a_max)
            break
        count += 1
    print(count)


if __name__ == '__main__':
    main()

Solution (Python):
N,H=map(int,input().split())
ab=[[0]*2 for i in range(N)]
for i in range(N):
  ab[i]=list(map(int,input().split()))
ab.sort(key=lambda x:x[0])
max_katana=ab[-1]
ab.sort(reverse=True,key=lambda x:x[1])
count=0
for i in range(N):
  if H > 0:
    if ab[i][1] >= max_katana[0]:
      H -= ab[i][1]
      count+=1
    else:
      break
if H > 0:
  if H % max_katana[0]==0:
    count+= H // max_katana[0]
  else:
    count+= (H // max_katana[0]) + 1
print(count)

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



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



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

Solution (Python):
n, h, *k = map(int, open(0).read().split())
a = max(k[::2]); b = sorted(k[1::2], reverse = True)

ans = 0
while ans < n and b[ans] > a and h > 0:
    h -= b[ans]
    ans += 1
if h > 0: ans += (h + a - 1) // a
print(ans)

Solution (Python):
n, h, *k = map(int, open(0).read().split())

a = 0; b = []
for i, j in zip(*[iter(k)]*2):
    a = max(a, i)
    b.append(j)
b = sorted(b, reverse = True)

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

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

Solution (Python):
from collections import Counter,defaultdict
import sys,heapq,bisect,math,itertools,string,queue
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,h = inpl()
max_a = 0
bb = []
for i in range(n):
    a,b = inpl()
    bb.append(b)
    max_a = max(max_a, a)
bb.sort()
rr = bisect.bisect_left(bb,max_a)

sum_b = 0
cnt = 0
for i in range(n-1,rr-1,-1):
    sum_b += bb[i]
    cnt += 1
    if sum_b >= h:
        print(cnt)
        break
else:
    print(cnt + math.ceil((h-sum_b)/max_a))

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

def solve():
  n,h = (int(i) for i in input().split())
  amax = -99
  b = []
  for i in range(n):
    ta,tb = (int(i) for i in input().split())
    amax = max(amax,ta)
    b.append(tb)

  b = deque(sorted(b,reverse=True))
  
  damage = 0
  ct = 0
  while damage < h:
    if len(b):
      throw = b[0]
    else:
      throw = -99
      
    if throw > amax:
      b.popleft()
      ct += 1
      damage += throw
      continue
    else:
      sabun = h-damage
      ct += math.ceil(sabun/amax)
      damage += amax*math.ceil(sabun/amax)
  print(ct)
solve()

Solution (Python):
import sys
input = sys.stdin.readline
from collections import deque
import math
def solve():
  n,h = (int(i) for i in input().split())
  a = []
  b = []
  for i in range(n):
    ta,tb = (int(i) for i in input().split())
    a.append(ta)
    b.append(tb)
  amax = max(a)
  b = deque(sorted(b,reverse=True))
  
  damage = 0
  ct = 0
  while damage < h:
    if len(b):
      throw = b[0]
    else:
      throw = -99
      
    if throw > amax:
      throw = b.popleft()
      ct += 1
      damage += throw
      continue
    else:
      sabun = h-damage
      ct += math.ceil(sabun/amax)
      damage += amax*math.ceil(sabun/amax)
  print(ct)
solve()

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




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


B = sorted([b for b in B if b > maxA], reverse=True)

cnt = 0
for b in B:
    cnt += 1
    H -= b
    if H <= 0:
        break
if H > 0:
    q, r = divmod(H, maxA)
    cnt += q + (1 if r > 0 else 0)
print(cnt)

Solution (Python):


N,H=map(int,input().split())
l=[[-1]*2 for i in range(N)]
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
is_killed=False

for i in range(N):
    if B[i]>A[0]:
        H-=B[i]
        count+=1
    if H<1:
        is_killed=True
        break

if is_killed:
    print(count)
else:    
    print(count-(-H//A[0]))

Solution (Python):
import collections

def main():

    N, H = map(int, input().split())
    sword = []
    for _ in range(N):
        a, b = map(int, input().split())
        sword.append([a, b])
    sword.sort(key = lambda x: x[1], reverse= True)

    count = float('inf')

    
    damage = 0
    count1 = 0
    for a, b in sword:
        damage += b
        count1 += 1
        if damage >= H:
            break
    if damage >= H:
        count = min(count, count1)

    
    sword.sort(key = lambda x: x[0], reverse = True)
    a0, b0 = sword.pop(0) 
    sword.sort(key = lambda x: x[1], reverse = True)

    damage = 0
    count2 = 0
    i = 0
    while i < len(sword) and sword[i][1] > a0:
        damage += sword[i][1]
        count2 += 1
        i += 1
    if damage + b0 < H:
        c = (H - damage - b0) // a0
        if (H - damage - b0) % a0 != 0:
            c += 1
        count2 += c + 1
        count = min(count, count2)

    return count


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

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, h = list(map(int, input().rstrip('\n').split()))
    ma = 0
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        ma = max(ma, a)
        bl.append(b)
    bl.sort()
    cnt = 0
    while True:
        if h <= 0:
            print(cnt)
            exit()
        elif len(bl) != 0:
            b = bl.pop()
            if ma < b:
                h -= b
                cnt += 1
            else:
                cnt += ((h + ma - 1) // ma)
                print(cnt)
                exit()
        else:
            cnt += ((h + ma - 1) // ma)
            print(cnt)
            exit()



if __name__ == '__main__':
    slove()

Solution (Python):
from collections import deque
import math
n, h = map(int, input().split())
a_list = []
b_list = []
time = 0
for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
a_list.sort()
b_list.sort(reverse=True)
b_stack = deque(b_list)
while h > 0:
    if len(b_stack) > 0:
        if a_list[-1] < b_stack[0]:
            h -= b_stack.popleft()
            time += 1
        else:
            
            time += math.ceil(h / a_list[-1])
            h = 0
    else:        
        time += math.ceil(h / a_list[-1])
        h = 0
    
print(time)

Solution (Python):
import math
N , H = map(int , input().split())
slash = []
throw = []
for _ in range(N):
    a , b = map(int , input().split())
    slash.append(a)
    throw.append(b)
count = 0

slash_max = max(slash)

throw.sort(reverse = True)

while H > 0:
    
    if not throw or throw[0] < slash_max :
        count += math.ceil(H / slash_max)
        break
    else:
        H -= throw[0]
        throw.pop(0)
        
    count += 1
print(count)

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

    A = [0] * N
    B = [0] * N

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

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

    print(ans)

main()

Solution (Python):
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor


INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() 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)]
mod = 1000000007


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



max_a = max(A)
B.sort(reverse=True)
ret = 0
i = 0
while i < n and ret < h and B[i] > max_a:
    ret += B[i]
    i += 1


if ret < h:
    i += ceil((h - ret) / max_a)


print(i)

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)

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

score = 0
for i in range(N):
    if B[i] <= A[0]:
        i = i - 1
        break
    score += B[i]
    if score >= H:
        print(i + 1)
        exit()

print(math.ceil((H - score) / A[0]) + i + 1)

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

def solve(H) :
    ret = 0
    ab.sort(key=lambda x: x[1], reverse=True)
    for a, b in ab :
        if b > amax :
            H -= b
            ret += 1
        else :
            break
            
        if H <= 0 :
            return ret
            
    ret += (H + amax - 1) // amax
    return ret

print(solve(H))

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

Solution (Python):
def main():
    N, H = map(int, input().split())
    a = 0
    b = []
    for i in range(N):
        t = list(map(int, input().split()))
        a = max(a, t[0])
        b.append(t[1])
    b = sorted(b, reverse=True)
    
    
    i = 0
    while b[i] > a and H > 0:
        H -= b[i]
        i += 1
        if i >= N:
            break
    if H > 0:
        if H%a == 0:
            i += H//a
        else:
            i += H//a + 1
    print(i)

if __name__ == "__main__":
    main()

Solution (Python):
import math
N,H=(int(x) for x in input().split())
a=[]
b=[]
for n in range(N):
    aa,bb=(int(x) for x in input().split())
    a.append(aa)
    b.append(bb)
a_sort=sorted(a)
b_sort=sorted(b)
count=0
for n in range(N):
    if b_sort[N-1-n]>a_sort[N-1]:
        H=H-b_sort[N-1-n]
        count+=1
        if H<=0:
            break
if H>0:
    count=count+H//a_sort[N-1]
    if H%a_sort[N-1]>0:
        count+=1
print(count)

Solution (Python):
import math
N,H=(int(x) for x in input().split())
a=[]
b=[]
for n in range(N):
    aa,bb=(int(x) for x in input().split())
    a.append(aa)
    b.append(bb)
a_sort=sorted(a)
b_sort=sorted(b)
count=0
for n in range(N):
    if b_sort[N-1-n]>a_sort[N-1]:
        H=H-b_sort[N-1-n]
        count+=1
        if H<=0:
            break
if H>0:
    count=count+H//a_sort[N-1]
    if H%a_sort[N-1]>0:
        count+=1
print(count)

Solution (Python):

def updiv(x,y):
    if x % y == 0:
        return x // y
    else:
        return x // y + 1


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

now = 0

lis = []
dic = {}

for i in range(N):

    a,b = map(int,input().split())

    if a not in dic:
        lis.append(a)
        
    dic[a] = float("inf")
        
    if b not in dic:
        lis.append(b)

    if b in dic:
        dic[b] += 1
    else:
        dic[b] = 1

lis.sort()
lis.reverse()
ans = 0

for i in lis:

    if dic[i] * i < H:
        ans += dic[i]
        H -= dic[i] * i

    else:
        ans += updiv(H,i)
        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())
m=max(a);b.sort();c=0
while h>0:
 if b and b[-1]>m:c+=1;h-=b.pop()
 else:c-=h//-m;h=0
print(c)

Solution (Python):
def slove():
    import sys
    input = sys.stdin.readline
    n, h = list(map(int, input().rstrip('\n').split()))
    a = []
    b = []
    for i in range(n):
        ta, tb = list(map(int, input().rstrip('\n').split()))
        a.append(ta)
        b.append(tb)
    ma = max(a)
    b.sort()
    cnt = 0
    for i in range(10 ** 20):
        if len(b) != 0:
            pb = b.pop()
            if pb > ma:
                cnt += 1
                h -= pb
                if h <= 0:
                    print(cnt)
                    exit()
            else:
                cnt += ((h + ma - 1) // ma)
                print(cnt)
                exit()
        else:
            cnt += ((h + ma - 1) // ma)
            print(cnt)
            exit()


if __name__ == '__main__':
    slove()

Solution (Python):
import math

N, H = map(int, input().split())
Swords_a = []
Swords_b = []
for i in range(N):
  
  a, b = map(int, input().split())
  Swords_a.append(a)
  Swords_b.append(b)
  
ma = max(Swords_a)
sb = 0 

Swords_b = sorted(Swords_b, reverse = True)

c = 0
k = 0

for i in range(N):
  if ma < Swords_b[i]:
    sb += Swords_b[i]
    c += 1
  if sb >= H:
    k = c
    break

if sb < H:
  print(c + math.ceil((H-sb)/ma))
else:
  print(k)

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

a=[]
b=[]

for _ in range(n):
  aa,bb =map(int,input().split())
  a.append(aa)
  b.append(bb)
  
b.sort()
c=max(a)
b=b[::-1]


count=0
damage=0

for item in b:
  if item>=c and damage<h:
    damage+=item
    count+=1
  else:
    break

if damage >= h:
  print(count)
else:
  print(count+((damage-h)//c)*(-1))

Solution (Python):
import sys,bisect
input=sys.stdin.readline
n,h=map(int,input().split())
B=[]
Amax=0
for _ in range(n):
    a,b=map(int,input().split())
    Amax=max(a,Amax)
    B.append(b)
B.sort()
BB=B[bisect.bisect_left(B,Amax):]
cnt=0

while h>0:
    if BB:
        b=BB.pop()
        h-=b
        cnt+=1
    else:
        if h%Amax==0:
            cnt+=h//Amax
        else:
            cnt+=(h//Amax)+1
        h=0

print(cnt)

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

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

max_a = max(A)

B = [b for b in B if b > max_a]
B = sorted(B, reverse=True)

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

if H > 0:
    ans += int((H+max_a-0.1)//max_a)

print(ans)

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

amax = A[0]
res = 0
damage = 0
for b in B:
    if b <= amax:
        break
    res += 1
    damage += b
    if damage >= H:
        break
if damage < H:
    res += ((H-damage-1)//amax + 1)
print(res)

Solution (Python):
NH = input().split()
N = int(NH[0])
H = int(NH[1])
a = []
b = []
for v in range(N):
    L = input().split()
    a.append(L[0])
    b.append(L[1])
a = list(map(int, a))
b = list(map(int, b))
a.sort(reverse = True)
b.sort(reverse = True)
c = 0
count = 0
while c < H:
    if len(b) > 0 and a[0] < b[0]:
        c = c + b.pop(0)
        count = count + 1 
    else:
        break
if c < H:
    count = count -(-(H - c)//a[0])
print(count)

Solution (Python):
from heapq import heappop, heappush
n, h = map(int, input().split())
T = []
for i in range(n):
    a, b = map(int, input().split())
    T.append((a, -b))

max_a, minus_min_b_of_max_a = max(T)
min_b_of_max_a = -minus_min_b_of_max_a
T.remove((max_a, minus_min_b_of_max_a))

H = []
for i in range(n-1):
    a, minus_b = T[i]
    heappush(H, (minus_b, a))

cnt = 0
while h > 0 and H:
    if min_b_of_max_a >= h:
        h -= min_b_of_max_a
        cnt += 1
        break

    minus_b, a = heappop(H)
    b = -minus_b

    if b <= max_a:
        break
    else:
        h -= b
        cnt += 1


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

print(cnt)

Solution (Python):
from heapq import heappop, heappush
n, h = map(int, input().split())
T = []
for i in range(n):
    a, b = map(int, input().split())
    T.append((a, -b))

max_a, min_b_of_max_a = max(T)
min_b_of_max_a = - min_b_of_max_a
T.remove((max_a, -min_b_of_max_a))

H = []
for i in range(n-1):
    a, minus_b = T[i]
    heappush(H, (minus_b, a))

cnt = 0
while h > 0:
    if min_b_of_max_a >= h:
        h -= min_b_of_max_a
        cnt += 1
        break

    if H:
        b, a = heappop(H)
        b = -b
    else:
        break

    if b <= max_a:
        break
    else:
        h -= b
        cnt += 1


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

print(cnt)

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)

alist = sorted(alist)[::-1]
blist = sorted(blist)[::-1]

ans = 0
i = 0

while i < len(blist):
  if alist[0] >= blist[i]:
    break
  h -= blist[i]
  ans += 1
  if h <= 0:
    print(ans)
    exit()  
  i += 1

if h % alist[0] == 0:
  ans += h // alist[0]
  print(ans)
else:
  ans += (h // alist[0]) + 1
  print(ans)

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

Solution (Python):
import math


def resolve():
    n, h = map(int, input().split())
    ab = list(list(map(int, input().split())) for _ in range(n))
    ab.sort(key=lambda x: (x[0], x[1]), reverse=True)
    max_a = ab[0][0]
    count = 0
    throwers = sorted([b for _, b in ab if b > max_a], reverse=True)
    for t in throwers:
        h -= t
        count += 1
        if h <= 0:
            return count
    count += math.ceil(h / max_a)
    return count


if __name__ == "__main__":
    print(resolve())