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())
mxa = 0
dmg = 0
cnt = 0
di = []
for i in range(n):
    a,b = map(int,input().split())
    di.append(b)
    if a > mxa:
        mxa = a
di.sort(reverse=True)
for j in di:
    if j >= mxa:
        dmg += j
        cnt += 1
        if dmg >= h:
            break
if dmg < h:
    cnt += (h-dmg)//mxa
    if (h-dmg)%mxa != 0:
        cnt += 1
print(cnt)

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

A = []
B = []
for a, b in AB:
    A.append(a)
    B.append(b)

max_A = max(A)
C = sorted([b for b in B if b >= max_A], reverse=True)

cnt = 0
for c in C:
    h -= c
    cnt += 1
    if h <= 0:
        print(cnt)
        exit()

atack = h // max_A
cnt += atack
h -= atack * max_A
if h <= 0:
    print(cnt)
else:
    print(cnt+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)

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

i = 0
while H > 0:
    if i < n:
        if amax < b[i]:
            H -= b[i]
            ans += 1
            i += 1
        else:
            ans += H//amax
            if H%amax != 0:
                ans += 1
            break
    else:
        ans += H//amax
        if H % amax != 0:
            ans += 1
        break

print(ans)

Solution (Python):
import sys


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



def main():
    n, h = [int(i) for i in input().strip().split()]
    attack = []
    throw = []
    for _ in range(n):
        a, t = [int(i) for i in input().strip().split()]
        attack.append(a)
        throw.append(t)

    a_max = max(attack)
    throw = sorted(throw)[::-1]
    cnt = 0
    for t in throw:
        if t > a_max:
            h -= t
            cnt += 1
        elif t <= a_max:
            break
        if h <= 0:
            print(cnt)
            return
    if h > 0:
        cnt += h // a_max
        if h % a_max > 0:
            cnt += 1
    print(cnt)

    return


if __name__ == "__main__":
    main()

Solution (Python):
import sys
input = sys.stdin.readline
N, H = map(int, input().split())
a = [tuple(map(int, input().split())) for _ in range(N)]
a.sort(key = lambda x: -x[1])
cs = [0] * (N + 1)
mx = 0
for i in range(N):
  cs[i + 1] = cs[i] + a[i][1]
  mx = max(mx, a[i][0])
res = H + 1
for i in range(N + 1): res = min(res, -(-max(0, H - cs[i]) // mx) + i)
print(res)

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

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





def is_OK(x):
    count = 0
    damage = 0
    for n in range(N):
        if B[n] > max_a and count < x:
            count += 1
            damage += B[n]
    damage += (x-count) * max_a
    if H - damage <= 0:
        return True
    else:
        return False


ng, ok = 0, 10**9+1
while ok - ng > 1:
    mid = ng + (ok - ng) // 2
    if is_OK(mid):
        ok = mid
    else:
        ng = mid

print(ok)

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

for _ in range(n):
    c1, c2 = map(int, input().split())
    a = max(a, c1)
    b.append(c2)
b = sorted(b, reverse=True)

def count(ans, num):
    if num.is_integer():
        ans += int(num)
    else:
        ans += int(num)+1
    print(ans)
    sys.exit()
    

i = 0
while h > 0:
    if i == len(b):
        count(ans, h/a)
    elif a >= b[i]:
        count(ans, h/a)
    else:
        h -= b[i]
        ans += 1
        i += 1
print(ans)

Solution (Python):
import sys

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],B[i]=a,b

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

K=0
for b in B:
    if H>0 and b>=max_A:
        K+=1
        H-=b

if H>0:
    K+=(H+max_A-1)//max_A

print(K)

Solution (Python):
from math import ceil
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)
mb = [i for i in b if i > ma]
mb.sort(reverse=True)
if sum(mb) >= h:
    i = 0
    while h > 0:
        h -= mb[i]
        i += 1
    print(i)
else:
    cnt = len(mb)
    h -= sum(mb)
    print(cnt + ceil(h/ma))

Solution (Python):
import sys
input = sys.stdin.readline
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())
a_max = max(a)
b_thr = []
for i in b:
    if i > a_max:
        b_thr.append(i)
b_thr.sort(reverse=True)
ans = 0
for i in b_thr:
    if h > 0:
        h -= i
        ans += 1
    else:
        print(ans)
        exit()
if h % a_max == 0:
    ans += h // a_max
else:
    ans += h // a_max + 1
print(ans)

Solution (Python):
n, h = map(int, input().split())
alst = []
blst = []
for _ in range(n):
    a, b = map(int, input().split())
    alst.append(a)
    blst.append(b)
blst.sort(reverse = True)
a = max(alst)
ans = 0
for num in blst:
    if num < a:
        ans += (h - 1) // a + 1
        break
    else:
        ans += 1
        h -= num
        if h <= 0:
            break

else:
    ans += (h - 1) // a + 1
print(ans)

Solution (Python):
import sys
read=sys.stdin.read

def main():
  n,h,*ab=map(int,read().split())
  tops=max(ab[0::2])
  tlst=[b for b in ab[1::2] if b>tops]
  tlst.sort(reverse=True)
  i=-1
  t=0
  for i,t in enumerate(tlst):
    h-=t
    if h<=0:
      h=0
      break
  print(h//tops+(h%tops>0)+i+1)

if __name__=='__main__':
  main()

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

Solution (Python):




n, h = map(int, input().split())
power = [list(map(int, input().split())) for _ in range(n)]
maxa = sorted(power, key=lambda x : x[0], reverse=True)[0][0]
muscleb = sorted(list(filter(lambda x : x[1] >=  maxa, power)), key = lambda x : x[1], reverse=True)
ans = 0
for m in muscleb:
    ans += 1
    h -= m[1]
    if h <= 0:
        print(ans)
        exit()
additionala = h // maxa
if h % maxa != 0:
    additionala += 1
print(additionala + ans)

Solution (Python):
n,h = map(int,input().split())
al,bl = [],[]
for i in range(n):
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
ma = max(al)
bl.sort()
s = 0
c = 0
for i in bl[::-1]:
  if ma >= i:
    break
  else:
    s += i
    c += 1
    if s >= h:
      break
if h > s:
  c += (h-s-1)//ma+1
print(c)

Solution (Python):
import bisect
import math

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

am = 0
Bs = []

for _ in range(N):
  a,b = map(int, input().split())
  am = max(am, a)
  Bs.append(b)
  
Bs.sort()
j = bisect.bisect_right(Bs, am)

rlt = 0
for i in range(N-1, j-1, -1):
  H -= Bs[i]
  rlt += 1
  if H <= 0:
    break
    
if H > 0:
  rlt += math.ceil(H/am)
  
print(rlt)

Solution (Python):
from bisect import bisect_left

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

B = sorted(B)
idx = bisect_left(B,amax)
B = B[idx:][::-1]
cum=[0]
for i in range(len(B)):
  cum += [cum[-1]+B[i]]
  if cum[-1]>=H:
    print(i+1)
    exit()
print(len(B) + ((H-cum[-1])+amax-1)//amax)

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

B.sort(reverse=True)
ans = 0
n = max(A)
flag = True
for i in range(N):
  if B[i] > n:
    ans += 1
    H -= B[i]
    if H <= 0:
      flag = False
      break
  else:
    break
if flag:
  ans += H // n
  if H % n != 0:
    ans += 1
print(ans)

Solution (Python):
import sys
from itertools import accumulate
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, H, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

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

    i = bisect_left(B, H)
    if i < len(B):
        ans = i + 1
    else:
        ans = len(B) + (H - B[-1] + Amax - 1) // Amax

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys
from itertools import accumulate
from bisect import bisect_left

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, H, *AB = map(int, read().split())
    A = AB[::2]
    B = AB[1::2]

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

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

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

    print(ans)
    return


if __name__ == '__main__':
    main()

Solution (Python):


import math
N, H = map(int, input().split())
swing = []
throw = []
for _ in range(N):
    sw, th = map(int, input().split())
    swing.append(sw)
    throw.append(th)
swing.sort(reverse=True)
throw.sort(reverse=True)
'''
idx = bisect.bisect_right(throw, swing[0])
if idx == len(throw):
    print(math.ceil(H / swing[0]))
'''
if swing[0] >= throw[0]:
    print(math.ceil(H / swing[0]))
else:
    
    cnt = 0
    damage_sum = 0
    while cnt < len(throw):
        if throw[cnt] <= swing[0]:
            break
        damage_sum += throw[cnt]
        cnt += 1
        if damage_sum >= H:
            print(cnt)
            exit()
    '''
    for i in reversed(throw):
        cnt += 1
        damage_sum += i
        if damage_sum >= H:
            print(cnt)
            exit()
    '''
    print(math.ceil(cnt + (H - damage_sum) / swing[0]))

Solution (Python):
import bisect
import math
N, H = map(int, input().split())
swing = []
throw = []
for _ in range(N):
    sw, th = map(int, input().split())
    swing.append(sw)
    throw.append(th)
swing.sort(reverse=True)
throw.sort()
idx = bisect.bisect_right(throw, swing[0])
if idx == len(throw):
    print(math.ceil(H / swing[0]))
else:
    throw = throw[idx:]
    cnt = 0
    damage_sum = 0
    for i in reversed(throw):
        cnt += 1
        damage_sum += i
        if damage_sum >= H:
            print(cnt)
            exit()
    print(math.ceil(cnt + (H - damage_sum) / swing[0]))

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

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

a = max(A)
cnt = 0

for b in sorted(B, reverse=True):
    if b < a:
        break
    H -= b
    cnt += 1
    
    if H <= 0:
        print(cnt)
        exit(0)

cnt += H // a
if H % a != 0:
    cnt += 1
print(cnt)

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

a_ls = [0]*N
b_ls =[0]*N
for i in range(N):
    a, b = map(int,input().split())
    a_ls[i] = a
    b_ls[i] = -b

a_max = max(a_ls)

heapq.heapify(b_ls)

total = 0
count = 0
for i in range(len(b_ls)):
    b_max = -heapq.heappop(b_ls)

    if a_max>=b_max:
        count += math.ceil((H-total)/a_max)
        total = H
        break
    total += b_max
    count +=1

    if total >=H:
        break

count += math.ceil(max(0,(H-total))/a_max)

print(count)

Solution (Python):
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
r,m,cumul = h, max(ais)[0],0
r = (h+m-1)/m
for i in range(len(ais)):
	cumul += ais[i][1]
	r = min(r, i + 1 + (max(h - cumul, 0) + m - 1)/ m )
	if h <= cumul:
		break
print r

Solution (Python):
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
r,m,cumul = h, max(ais)[0],0
r = (h+m-1)/m
for i in range(-1,len(ais)):
	if i >= 0: cumul += ais[i][1]
	r = min(r, i+1 + (max(h - cumul, 0) + m-1)/m)
print r

Solution (Python):
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
r,m,cumul = h, max(ais)[0],0
for i in range(-1,len(ais)):
	if i >= 0: cumul += ais[i][1]
	r = min(r, i+1 + int(math.ceil(max(0,h - cumul) /  float(m))))
print r

Solution (Python):
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
m = max(ais)[0]
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]
	r = min(r, i+1 + math.ceil(max(0,h - cumul) /  float(m)))
print int(r)

Solution (Python):
import math
n,h = map(int ,raw_input().split())
ais = [map(int, raw_input().split()) for _ in range(n)]
ais.sort(key = lambda x: (-x[1],x[0]))
cumul = 0
r = +float('inf')
m = max(ais)[0]
for i in range(-1,len(ais)):
	if i >= 0:
		cumul += ais[i][1]

	if cumul >= h:
		r = min(r, (i+1))
		break
	else:
		r = min(r, i+1 + math.ceil(abs(h - cumul) /  float(m)))
print int(r)

Solution (Python):
import sys
mina=10**10
def waru(a,b):
  if a%b==0:
    return a//b
  else:
    return (a//b)+1
N,H=map(int,input().split())
A=list()
B=list()
for i in range(N):
  a,b=map(int,input().split())
  A.append(a)
  B.append(b)
ma=max(A)
ind=A.index(ma)
B=[i for i in B if i>ma]
B=sorted(B,reverse=True)
cou=1
s=0
for i in range(len(B)):
  s+=B[i]
  if H<=s:
    print(i+1)
    sys.exit()
H=H-s
print(len(B)+waru(H,ma))

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines



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

q = []
for i in range(N):
    a, b = map(int, input().split())
    heapq.heappush(q,(-a, True))
    heapq.heappush(q,(-b, False))

ans = 0
while H > 0:
    x = heapq.heappop(q)
    if not x[1]:
        H -= abs(x[0])
        ans += 1
    else:
        ans += (H + abs(x[0]) - 1) // abs(x[0])
        break
print(ans)

Solution (Python):

printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7


def ddprint(x):
  if DBG:
    print(x)

n,h = inm()
if n==-1 and h==10:
    3/0
a = []
b = []
for i in range(n):
    aa,bb = inm()
    a.append(aa)
    b.append(bb)
a.sort()
b.sort()
c = a[-1]
x = 0
while len(b)>0 and b[-1]>c:
    h -= b[-1]
    x += 1
    
    b.pop()
    if h<=0:
        print(x)
        exit()
x += (h+c-1)//c
print(x)

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, H = [int(item) for item in input().split()]
    ab = [[int(item) for item in input().split()] for _ in range(N)]
    ab.sort(reverse=True, key=lambda x:x[1])
    a_max_ab = max(ab, key=lambda x:x[0])

    cnt = 0    
    for a, b in ab:
        if b > a_max_ab[0]:
            H -= b
            cnt += 1
        
        if H <= 0:
            break

    if H > 0:
        cnt += H // a_max_ab[0]
        if H  % a_max_ab[0] != 0:
            cnt += 1

    print(cnt)


if __name__ == "__main__":
    resolve()

Solution (Python):
import sys

N, H = map(int, sys.stdin.readline().split())

katanas = []
for i in range(N):
    a, b = map(int, sys.stdin.readline().split())
    katanas.append((a, b, i))

sk = sorted(katanas, reverse=True)
max_k = sk[0][0]

katanas.sort(key = lambda x:x[1], reverse=True)
ans = 0
i = 0
while H > 0:
    if i < N and katanas[i][1] > max_k:
        H -= katanas[i][1]
        i += 1
        ans += 1
    else:
        tmp = (H - 1) // max_k + 1
        H -= tmp * max_k
        ans += tmp
        
print(ans)

Solution (Python):


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

A = []
B = []

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

A = sorted(A)[::-1]
B = sorted(B)[::-1]

ret = 0
if B[0] < A[0]:
    if H % A[0] == 0: ret = H // A[0]
    else: ret = H // A[0] + 1
    H = 0
else:
    for b in B:
        if b < A[0]:
            if H%A[0] == 0: ret += H // A[0]
            else: ret += H // A[0] + 1
            H = 0
            break
        else:
            ret += 1
            H -= b

        if H <= 0:
            break

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


print(ret)

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)[::-1]
B = sorted(B)[::-1]

ret = 0
if B[0] < A[0]:
    if H % A[0] == 0: ret = H // A[0]
    else: ret = H // A[0] + 1
    H = 0
else:
    for b in B:
        if b < A[0]:
            if H%A[0] == 0: ret += H // A[0]
            else: ret += H // A[0] + 1
            H = 0
            break
        else:
            ret += 1
            H -= b

        if H <= 0:
            break

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


print(ret)

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

Solution (Python):
import math

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

A=[]
B=[]

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

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


nage = 0
ans = math.ceil((H+maxA)/maxA)
for i in range(N):
    nage+=B[i]
    ans = min(ans, (i+1) + math.ceil((max(0,H-nage))/maxA))

print(ans)

Solution (Python):
import heapq
n,h= map(int,input().split())
bl = []
heapq.heapify(bl)
maxa = -1
for i in range(n):
    a,b=map(int,input().split())
    maxa=max(maxa,a)
    heapq.heappush(bl,-b)
count=0
while len(bl)>0:
    if -bl[0]>maxa:
        h-=-heapq.heappop(bl)
        count+=1
        if h<=0:break
    else:break
if h<=0:print(count)
else:print(count + h//maxa + (1 if h%maxa>0 else 0))

Solution (Python):
def main():
    import sys

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

    n, h = map(int, input().split())
    aa, bb = [], []
    for i in range(n):
        a, b = map(int, input().split())
        aa.append(a)
        bb.append(b)
    bb.sort(reverse=True)
    maxa = max(aa)
    cnt = 0
    i=0
    
    while i < n and h > 0:
        if bb[i] > maxa:
            h -= bb[i]
            cnt+=1
        i+=1
    if h > 0:
        cnt += (h+maxa-1)//maxa
        
    print(cnt)
        
        
if __name__ == '__main__':
    main()

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

a_max=0
b = []
N,H = map(int,input().split())
for i in range(N):
    an,bn = map(int,input().split())
    b.append(bn)
    a_max = max(a_max,an)

b = sorted([ bn for bn in b if bn>=a_max])
cnt = 0
for i in range(len(b)):
    H -= b.pop()
    cnt += 1
    if H <=0:
        print(cnt)
        exit()

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

Solution (Python):
import sys,math
import numpy as np
input = sys.stdin.readline

a_max=0
a = []
b = []
N,H = map(int,input().split())
for i in range(N):
    an,bn = map(int,input().split())
    b.append(bn)
    a_max = max(a_max,an)

b = np.array(b)
b = sorted(list(b[b>=a_max]))

cnt = 0
for i in range(len(b)):
    H -= b.pop()
    cnt += 1
    if H <=0:
        print(cnt)
        exit()

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

Solution (Python):
import sys,math
import numpy as np
input = sys.stdin.readline

b_max=0
a_max=0
a = []
b = []
N,H = list(map(int,input().split()))
for i in range(N):
    an,bn = list(map(int,input().split()))
    a.append(an)
    b.append(bn)
    a_max = max(a_max,an)
    b_max = max(b_max,bn)
a = np.array(a)
b = np.array(b)
b = sorted(list(b[b>=a_max]))

cnt = 0
for i in range(len(b)):
    H -= b.pop()
    cnt += 1
    if H <=0:
        print(cnt)
        exit()

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2






def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B_left = []
    for b in B:
        if amax < b:
            B_left.append(b)

    B_left = sorted(B_left, reverse=True)
    if len(B_left) > 0:
        ans = 0
        for i, b in enumerate(B_left):
            H -= b
            ans += 1
            if H <= 0:
                break
        if H > 0:
            ans += ceil(H / amax)
    else:
        ans = ceil(H / amax)
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2






def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B_left = []
    for b in B:
        if amax < b:
            B_left.append(b)

    B_left = sorted(B_left, reverse=True)
    if len(B_left) > 0:
        ans = 0
        for i, b in enumerate(B_left):
            if H > 0:
                H -= b
                ans += 1
            else:
                break
        if H > 0:
            ans += ceil(H / amax)
    else:
        ans = ceil(H / amax)
    print(ans)

if __name__ == '__main__':
    solve()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 9)

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')
from math import ceil, floor, log2






def solve():
    N, H = MI()
    A = [0] * N
    B = [0] * N
    amax = 0
    for i in range(N):
        a, b = MI()
        A[i] = a
        B[i] = b
        amax = max(amax, a)

    B = sorted(B, reverse=True)
    ans = 0
    for i, b in enumerate(B):
        if b > amax and H > 0:
            ans += 1
            H -= b
        else:
            break

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

    print(ans)

if __name__ == '__main__':
    solve()

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

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

b = []
for i in range(N):
    if ab[i][1] > a:
        b.append(ab[i][1])
b.sort(reverse=True)

w = True
c = 0
h = H
for i in range(len(b)):
    h -= b[i]
    c += 1
    if h <= 0:
        print(c)
        w = False
        break

if w:
    print(c + (h-1)//a + 1)

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

B.sort(reverse=True)
A.sort(reverse=True)
B=[x for x in B if x>A[0]]
cnt=0
for i in range(len(B)):
  H-=B[i]
  cnt+=1
  if H<=0:
    print(cnt)
    exit()

A.sort(reverse=True)
print(cnt-(-H//A[0]))

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect
from scipy.special import comb
import copy
sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


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


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


N, H = zz()
A, B = [0] * N, [0] * N

for i in range(N):
    A[i], B[i] = zz()
normal_atack = max(A)


sorted_B = sorted(B, reverse=True)
sum_B = [0]*N
sum_B[0] = sorted_B[0]
damege = 0
atack_num = 0
throw_damage = 0
ans = (-(-H // normal_atack))

for i in range(0, N):
    throw_damage += sorted_B[i]
    rest_H = H - throw_damage
    if (rest_H <= 0):
        ans = min(i+1, ans)
    else:
        ans = min(-(-rest_H // normal_atack)+i+1, ans)
    
    if (throw_damage >= H):
        break
print(ans)

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

a_max = max(a for a,b in AB)
B = [b for a,b in AB if b>a_max]
B.sort(reverse=True)
ans = 0

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

Solution (Python):
n, h = map(int, input().split())
sords = [list(map(int, input().split())) for _ in range(n)]
best = sorted(sords)[-1][0]
throw_damage = 0
cnt = 0
for i in sords:
    if i[1] > best:
        throw_damage += i[1]
        cnt += 1
if throw_damage >= h:
    sords.sort(key = lambda x:(-x[1],x[0]))
    throw_damage = 0
    cnt = 0
    for i in sords:
        throw_damage += i[1]
        cnt += 1
        if throw_damage >= h:
            print(cnt)
            exit()
print(cnt + (h - throw_damage) // best + ((h - throw_damage)%best != 0))

Solution (Python):
n,h=map(int,input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
a, b = [list(i) for i in zip(*ab)]
ab.sort(reverse=True)

bm=ab[0][1]
b.remove(bm)
b.sort()

c=0
while h>0:
  if h<=bm:
    c+=1
    break
  if len(b)>0:
    if b[-1]>ab[0][0]:
      h-=b.pop()
      c+=1
      continue
  c+=(h-bm-1)//ab[0][0]+2
  h=0

print(c)

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

for i in range(n):
    a_,b_ = map(int,input().split())
    a.append(a_)
    b.append(b_)
b.sort(reverse = True)
max_a = max(a)
ans =0

for i in range(n):
    ans +=1
    if max_a > b[i]:
        ans -=1
        break
    h -= b[i]
    if h <= 0:
        break
    
if h > 0: 
    d,f = divmod(h,max_a)
    ans += d
    if f != 0:
        ans +=1
print(ans)

Solution (Python):
import sys
def input():return sys.stdin.readline().strip()

def main():
    N, H = map(int, input().split())
    info = [tuple(map(int, input().split())) for _ in range(N)]
    A_MAX = max(a for a, _ in info)
    Bs = [b for _, b in info if b > A_MAX]

    Bs.sort(reverse=True)
    ans = 0
    for b in Bs:
        if H <= 0:
            break
        ans += 1
        H -= b

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

if __name__ == "__main__":
    main()

Solution (Python):
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
a_sort = sorted(AB,key=lambda x: x[0],reverse=True)
a_max = a_sort[0][0]

tmp = []
for a,b in AB:
    if b > a_max:
        tmp.append(b)

tmp.sort(reverse=True)

cnt = 0
for i in tmp:
    H -= i
    cnt += 1
    if H <= 0:
        print(cnt)
        exit()

print(H // a_max + cnt if H % a_max == 0 else H // a_max + 1 + cnt)

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

amax = max(a)
b.sort(reverse=True)
cnt = 0
bsum = 0
for i in range(n):
    if b[i] <= amax or bsum >= h:
        break
    else:
        bsum += b[i]
        cnt += 1
h -= bsum
if h > 0:
    cnt += h//amax
    h -= amax * (h//amax)
if h > 0:
    h -= amax
    cnt += 1
print(cnt)

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

amax = max(a)
b.sort(reverse=True)
cnt = 0
while h > 0:
    if b and b[0] > amax:
        h -= b.pop(0)
        cnt += 1
    else:
        cnt += h//amax
        h -= amax * (h//amax)
        if h > 0:
            h -= amax
            cnt += 1
print(cnt)

Solution (Python):
import math
n,h=map(int,input().split())
furu=[None]*n
nageru=[None]*n
for i in range(n):
    a,b=map(int,input().split())
    furu[i]=a
    nageru[i]=b
rep=max(furu)
nagekaku=[]
for i in range(n):
    if rep<nageru[i]:
        nagekaku.append(nageru[i])
nage_sum=sum(nagekaku)
if nage_sum>=h:
    nagekaku=sorted(nagekaku,reverse=True)
    ans=0
    for i in range(len(nagekaku)):
        h-=nagekaku[i]
        ans+=1
        if h<=0:
            break
else:
    ans=len(nagekaku)
    h-=nage_sum
    ans+=math.ceil(h/rep)

print(ans)