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 sys
import collections


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    al = []
    bl = []
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        al.append(a)
        bl.append(b)
    al.sort()
    bl.sort()
    al = collections.deque(al)
    bl = collections.deque(bl)
    k = al[-1]
    cnt = 0
    while True:
        if len(bl) != 0:
            p = bl.pop()
            if p > k and h != 0:
                h -= min(p, h)
                cnt += 1
            else:
                print(cnt + (h + k - 1) // k)
                exit()
        else:
            print(cnt + (h + k - 1) // k)
            exit()


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
mod = 10**9 + 7
inf = float('inf')

N, H = LI()
a = [0]*N; b = [0]*N
for i in range(N):
    a[i], b[i] = LI()
maxa = max(a)
usefulb = []
for i in b:
    if i>maxa:
        usefulb.append(i)

usefulb.sort(reverse = True)
cur = int(0)
LastH = H
for v in usefulb:
    LastH -= v
    cur +=1
    if LastH<=0:
        break

if LastH>0:
    cur += ((LastH+maxa-1)//maxa)

ans = cur
print(ans)

Solution (Python):
from math import ceil
import sys

N,H = map(int,input().split())
maxA = -float('inf')
B = []
for _ in range(N):
  a,b = map(int,sys.stdin.readline().split())
  maxA = max(maxA,a)
  B.append(b)

B.sort(reverse=True)

ans = float('inf')
pointB = 0
for nb in range(N+1):
  if nb != 0: pointB += B[nb-1]
  ans = min(ans,max(0,ceil((H-pointB)/maxA))+nb)
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n,h=map(int,input().split())
bnowa=0
ab=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[1])
ab.sort(key=lambda x:x[0], reverse=True)
abb=ab[1:]
abb.sort(key=lambda x:x[1], reverse=True)
i=0
ans=0
while i<n-1 and h>0:
    if abb[i][1]<=ab[0][0]:
        break
    h-=abb[i][1]
    ans+=1
    i+=1
if h>0:
    h-=ab[0][1]
    ans+=1
    if h<=0:
        print(ans)
        exit()
    if h%ab[0][0]==0:
        ans+=h//ab[0][0]
    else:
        ans+=h//ab[0][0]+1
print(ans)

Solution (Python):
N, H = map(int, input().split())
a, b = zip(*(map(int, input().split()) for _ in range(N)))

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

result = 0


for x in b:
    result += 1
    H -= x
    if H <= 0:
        break



if H > 0:
    result += (H + (a_max - 1)) // a_max

print(result)

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

Solution (Python):
import sys
n,h=map(int,input().split())
l=[list(map(int,input().split())) for i in range(n)]
l.sort()
x=l[-1][0]
L=[]
for i in range(n):
  if l[i][1]>x:
    L.append(l[i][1])
L.sort()
L.reverse()
ct=0
for i in range(len(L)):
  h-=L[i]
  ct+=1
  if h<=0:
    print(ct)
    sys.exit()
print(ct+(h+x-1)//x)

Solution (Python):
import sys


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, h = list(map(int, input().rstrip('\n').split()))
    ab = [list(map(int, input().rstrip('\n').split())) for _ in range(n)]
    ab.sort(reverse=True)
    ma = ab[0][0]
    ab.sort(key=lambda x: x[1], reverse=True)
    cnt = 0
    for a, b in ab:
        if ma >= b or h <= 0:
            break
        else:
            h = max(h - b, 0)
            cnt += 1
    print(cnt + (h + ma - 1) // ma)


if __name__ == '__main__':
    solve()

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

ans = 0
for b in B:
    if b > A:
        H -= b
        ans += 1
    else:
        break
    if H <= 0:
        print(ans)
        sys.exit()

print((H-1)//A +1 +ans)

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

li_a = []; li_b = []

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

li_a = sorted(li_a,reverse=True)
li_b = sorted(li_b,reverse=True)

dmg = li_a[0]
ttl = 0
ans = 0

for i in range(n):
    if ttl >= h:
        break
    if li_b[i] <= dmg:
        break
    ttl += li_b[i]
    ans += 1

if ttl < h:
    if (h-ttl)%dmg == 0:
        ans += ((h-ttl)//dmg)
    else:
        ans += ((h-ttl)//dmg)+1


print(ans)

Solution (Python):
n,m=map(int,input().split())
l=[]
from math import ceil 
maxia=0 
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    if a>=maxia:
        maxia=a 
        ind=i 
have=[] 
for i in range(n): 
    if l[i][1]>maxia :
        have.append(l[i][1])
have.sort(reverse=1)
for i in range(len(have)): 
    m=m-have[i]
    if m<=0: 
        print(i+1)
        exit()
ans=len(have)
print(ans+ceil(m/maxia))

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

ans = 0
B.sort(reverse=True)

for i in range(N):
    if B[i] > max_a:
        H -= B[i]
        ans += 1
    else:
        break
    if H <= 0:
        break

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

Solution (Python):

import math

N, H = list(map(int, input().split()))
a_list = []
b_list = []

for _ in range(N):
    a, b = list(map(int, input().split()))
    a_list.append(a)
    b_list.append(b)

max_a = max(a_list)
b_list = sorted(b_list, reverse=True)
b_list = [b for b in b_list if b > max_a]
count = 0

while H > 0:
    if b_list:
        H -= b_list.pop(0)
        count += 1
    else:
        count += math.ceil(H / max_a)
        break

ans = count
print(ans)

Solution (Python):
import numpy as np
n,h = map(int,input().split())
amax = 0
lst = []
for i in range(n):
    a,b = map(int,input().split())
    amax = max(amax,a)
    lst.append(b)
lst.sort(reverse = True)

rui = np.cumsum(lst)
cnt = 10**10

for k in range(n):
    if rui[k] > h:
        cnt = min(cnt,k+1)
        break
    else:
        tmp = (h - rui[k]) // amax
        if (h - rui[k]) % amax != 0:
            tmp += 1
        cnt = min(cnt,k+tmp+1)
print(cnt)

Solution (Python):
def ceil(x, y):
  return (x -1) // y + 1

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

maxA = max(A)



cnt = 0
B.sort(reverse=True)
for i in B:
  if i >= maxA and H > 0:
    H -= i
    cnt += 1
  else:
    break
if H > 0:
  cnt += ceil(H, maxA)
print(cnt)

Solution (Python):
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = 0
H_ = H
flag = True
for j in sorted(throw_l)[::-1]:
    H_ -= j
    ans += 1
    if H_ <= 0:
        flag = False
        break
if flag:
    ans = (H - sum(throw_l))/swing_m
    ans = math.ceil(ans)
    print(ans+len(throw_l))
else:
    print(ans)

Solution (Python):
n, h = list(map(int, input().split()))
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
f = max(a)
b.sort()
for i in range(n):
    if b[i] <= f:
        b[i] = 0
    else:
        break

total = 0
count = 0
b.reverse()
for i in range(n):
    if b[i] == 0:
        break
    total += b[i]
    count += 1
    if total >= h:
        print(count)
        exit()
if (h - total) % f == 0:
    count += (h - total) // f
else:
    count += (h - total) // f
    count += 1
print(count)

Solution (Python):
n, h = list(map(int, input().split()))
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
f = max(a)
b.sort()
for i in range(n):
    if b[i] <= f:
        b[i] = 0
    else:
        break

total = 0
count = 0
b.reverse()
for i in range(n):
    if b[i] == 0:
        break
    total += b[i]
    count += 1
    if total >= h:
        print(count)
        exit()
if (h - total) % f == 0:
    count += (h - total) // f
else:
    count += (h - total) // f
    count += 1
print(count)

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

from operator import itemgetter

L.sort(reverse=True)
Amax = L[0]
L.sort(reverse=True, key=itemgetter(1))

i = 0
while i < N and Amax[0] < L[i][1] and H > 0:
    H -= L[i][1]
    i += 1
if H <= 0:
    ans = i
else:
    ans = i + H//Amax[0]
    if H%Amax[0] != 0:
        ans += 1
    
print(ans)

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

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()
ans = 0

for i in reversed(b[bisect_left(b, a[-1]):]):
    H -= i
    ans += 1
    if H <= 0:
        print(ans)
        exit()

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

Solution (Python):
import math

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

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

atack_damage = max(a_list)
b_list.sort(reverse=True)


throw_damage_list = []

for i in range(N):
  if b_list[i] > atack_damage:
    throw_damage_list.append(b_list[i])
  else:
    break

throw_total_damage = sum(throw_damage_list)


if throw_total_damage >= H:
  for i in range(N):
    H -= b_list[i]
    if H <= 0:
      print(i+1)
      break
else:
  H -= throw_total_damage
  
  
  print(len(throw_damage_list) + math.ceil(H/atack_damage))

Solution (Python):
import math
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())
huru = max(a)  
ans = 0
b = sorted(b, reverse=True)
for k in range(N):
    if b[k] < huru:
        break
    H -= b[k]
    ans += 1
    if H <= 0:
        break

if H > 0:
    ans += math.ceil(H / huru)
print(ans)

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

for i in range(n):
    if a<x[i][0]:
        a=x[i][0]

for i in range(n):
    if a<x[i][1]:
        b.append(x[i][1])
        
b.sort()
b.reverse()

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

Solution (Python):
import numpy as np


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

A = [None] * N
B = [None] * N

for n in range(N):
    A[n], B[n] = map(int, input().split())

A = sorted(A, reverse=True)
B = sorted(B, reverse=True)

S = np.cumsum(B)
try:
    S = S[:int(np.where(S >= H)[0])+1]
except:
    pass

result = H

for i, s in enumerate(S):
    result = min(result, i + 1 + int(np.ceil(max(0, H - S[i]) / A[0])))

print(result)

Solution (Python):
import math
n,h=map(int,input().split())
A=[0]*n
B=[0]*(n+1)
for i in range(n):
  A[i], B[i] = map(int, input().split())
a=max(A)
B.sort(reverse=True)
cnt=0
while h > 0:
  if a > B[0]:
    cnt+=math.ceil(h/a)
    h-=math.ceil(math.ceil(h/a)*a)
  else:
    cnt+=1
    h-=B[0]
    B.pop(0)
print(cnt)

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

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

A.sort()
B.sort()

if A[-1]>=B[-1]:
    print((H-1+A[-1])//A[-1])
    exit()

cnt=0
ans=[]

while B[-1]>A[-1]:
    H-=B[-1]
    cnt+=1
    if H<=0:
        ans.append(cnt)
        print(min(ans))
        exit()
    elif cnt==N:
        break
    B.pop()

ans.append(cnt+(H-1+A[-1])//A[-1])
print(min(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)

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

if amax>=B[0]:
    print((H-1+amax)//amax)
    exit()

cnt=0

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

print(cnt+(H-1+amax)//amax)

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


if __name__ == '__main__':
    slove()

Solution (Python):
import heapq

n,h = map(int, input().split())
cut = 0
throw = []
heapq.heapify(throw)

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

ans = 0
for i in range(n):
	num = heapq.heappop(throw)*(-1)
	if num > cut:
		 h -= num
		 ans += 1
		 if h <= 0:
			 print(ans)
			 exit()
	else:
		ans += (-(-h // cut))
		print(ans)
		exit()	
		
ans += (-(-h // cut))
print(ans)

Solution (Python):
import math

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







max_slash_damage = max(a)
damage_of_thrown_katanas = [x for x in b if x > max_slash_damage]
H_rest = H
ans = 0

n_slash = max(0, math.ceil((H_rest - sum(damage_of_thrown_katanas))/max_slash_damage))
H_rest -= max_slash_damage*n_slash
ans += n_slash

if H_rest <= 0:
    print(ans)
    exit()

damage_of_thrown_katanas.sort(reverse=True)
idx = 0

while H_rest > 0:
    H_rest -= damage_of_thrown_katanas[idx]
    idx += 1
    ans += 1

print(ans)

Solution (Python):

import sys, math


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    amax = max(a)
    bbig = sorted([bb for bb in b if bb > amax])
    if len(bbig) > 0:
        ss = sum(bbig)
        if ss < H:
            print(len(bbig) + math.ceil((H-ss)/amax))
        else:
            counter = 0
            sm = 0
            for bb in reversed(bbig):
                sm += bb
                counter += 1
                if sm >= H:
                    break
            print(counter)
    else:
        print(math.ceil(H/amax))
    return



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 = [list(map(int,input().split())) for _ in range(N)]
A = sorted(A,key=lambda x:x[1], reverse=True)
bmax = A[0][1]
A = sorted(A,key=lambda x:x[0],reverse=True)
for i in range(N):
    if i==0:
        A[i] = [A[i][0],A[i][1],1]
    else:
        A[i] = [A[i][0],A[i][1],0]
cnt = 0
tot = 0
ind = 0
a = A[0][0]
b = A[0][1]
if H<=bmax:
    cnt = 1
else:
    A = sorted(A,key=lambda x:x[1],reverse=True)
    for i in range(N):
        if tot+b>=H:
            cnt += 1
            ind=1
            break
        elif A[i][1]>=a and A[i][2]==0:
            tot += A[i][1]
            cnt += 1
        if tot>=H:
            ind = 1
            break
    if ind == 0:
        tot += b
        cnt += 1
        if tot<H:
            if (H-tot)%a==0:
                cnt += (H-tot)//a
            else:
                    cnt += (H-tot)//a+1
print(cnt)

Solution (Python):
n,h=map(int,input().split())
AB=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*AB)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if i>=a:
        h -=i
        count +=1
    if h<=0:print(count);exit()

print(count+(h//a) if h%a==0 else 1+count+(h//a))

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

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

while B[-1] < A[0]:
  B.pop()
S = 0
if sum(B) >= H:
  for i in range(N):
    S += B[i]
    if S >= H:
      print (i+1)
      break
else:
  H -= sum(B)
  print (math.ceil(H / A[0]) + len(B))

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.append(0)
a2 = sorted(a, reverse=True)
b2 = sorted(b, reverse=True)

count = 0
while True:
    if h <= 0:
        break
    elif b2[0] <= a2[0]:
        count += -(- h // a2[0])
        break
    else:
        h -= b2.pop(0)
        count += 1

print(count)

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)

am=max(A)
pop=[]
for i in reversed(range(N)):
  if B[i]<am:
    B.pop(i)
    A.pop(i)

n=0
for i in reversed(sorted(B)):
  if H<=0:
    print(n)
    exit()
  else:
    n+=1
    H-=i

print((H-1)//am+1+n)

Solution (Python):
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*A)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if h<=0:break
    elif i>=a:
        count +=1
        h -=i
if h>0:
    if h%a==0:count +=h//a
    else:count +=h//a+1

print(count)

Solution (Python):
n,h=map(int,input().split())
A=list(tuple(map(int,input().split())) for i in range(n))
A,B=zip(*A)
a=max(A)
count=0
for i in sorted(B)[::-1]:
    if h<=0:break
    elif i>=a:
        count +=1
        h -=i

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

print(count)

Solution (Python):

import sys


def solve(N: int, H: int, a: "List[int]", b: "List[int]"):
    a.sort(reverse=True)
    b = sorted([i for i in b if i > a[0]], key=lambda x:x, reverse=True)

    ans = 0
    s = 0
    while(s < H):
        if(len(b) == 0):
            from math import ceil
            print(ans + ceil((H-s)/a[0]))
            exit()
        
        s += b.pop(0)
        ans += 1

    print(ans)

    return



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):
from math import ceil
n,h = map(int,input().split())
ab = [tuple(int(i) for i in input().split()) for j in range(n)]
m = max(ab[i][0] for i in range(n))
ab.sort(key=lambda x: x[1],reverse=True)
ans = 0
for a,b in ab:
    
    if b <= m:
        break
    ans += 1
    h -= b
    if h <= 0:
        h = 0
        break
print(ans+ceil(h/m))

Solution (Python):
def d_katana_thrower():
    
    
    
    
    
    N, H = [int(i) for i in input().split()]
    Swords = [[int(i) for i in input().split()] for j in range(N)]
    max_swing = max([s[0] for s in Swords])
    sword_to_throw = sorted([s[1] for s in Swords if s[1] >= max_swing], reverse=True)

    threw_times = 0
    for damage in sword_to_throw:
        H -= damage
        threw_times += 1
        if H <= 0:
            return threw_times  
    return threw_times + -(-H // max_swing)

print(d_katana_thrower())

Solution (Python):
n,h=map(int,input().split())
k=[]
thrown=[False]*n
for i in range(n):
    a,b=map(int,input().split())
    k.append((a,0,i))
    k.append((b,1,i))
k.sort(key=lambda x:x[0],reverse=True)
ans=0
for i in range(2*n):
    if thrown[k[i][2]]:continue
    else:
        if k[i][1]==1:
            h-=k[i][0]
            ans+=1
            thrown[k[i][2]]==True
        elif k[i][1]==0:
            ans+=h//k[i][0]
            h%=k[i][0]
            if h!=0:
                ans+=1
                h-=k[i][0]
        if h<=0:break
print(ans)

Solution (Python):
n,h = map(int,input().split())
a = []
b = []
res = 0
for i in range(n):
    a1,b1=[int(i) for i in input().split()]
    a.append(a1)
    b.append(b1)

amax = max(a)
bthrow = [bs for bs in b if bs >= amax ]
bthrow.sort(reverse=True)
damage = 0 
while damage < h and res < len(bthrow):
    damage += bthrow[res]
    res += 1

if damage < h:
    res += (h-damage+amax-1) // amax

print(res)

Solution (Python):
def main():
    N, H = (int(i) for i in input().split())
    ab = [[int(i) for i in input().split()] for j in range(N)]
    a_max = -1
    a_max_idx = -1
    b_max = -1
    for i,v in enumerate(ab):
        b_max = max(b_max,v[1])
        if a_max < v[0]:
            a_max = v[0]
            a_max_idx = i
    b = [val[1] for i,val in enumerate(ab) if val[1] >= a_max]
    b.sort(reverse=True)
    ans = 0
    for throw in b:
        if H <= 0:
            break
        ans += 1
        H -= throw
    if 0 < H:
        from math import ceil
        ans += int(ceil(H/a_max))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import math

N,H=map(int,input().split())
AB=[]
for i in range(N):
    AB.append(list(map(int, input().split())))

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

nage=[]
for i in range(N):
    if AB[i][1] > ki:
        nage.append(AB[i][1])
nage.sort(reverse=True)

count=0
i=0
if nage!=[]:
    while H>0 and i<=len(nage)-1:
        H-=nage[i]
        count+=1
        i+=1

if H<=0:
    print(count)
else:
    print(count+math.ceil(H/ki))

Solution (Python):
swing=[]
throw=[]
import math

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

maxSwing=max(swing)

maxThrow=max(throw)

biggerlist=[]
bigsum=0
if maxSwing>=maxThrow:
    print(math.ceil(h/maxSwing))

elif maxSwing<maxThrow:
    for i in throw:
        if i>maxSwing:
            biggerlist.append(i)
            bigsum+=i
        else:
            continue
    biggerlists=sorted(biggerlist,reverse=True)

    if bigsum>h:
        suming=0
        for num in range(len(biggerlists)):
            suming+=biggerlists[num]
            if suming>=h:
                print(num+1)
                break
    elif bigsum==h:
        print(len(biggerlist))
    elif bigsum<h:
        left=h-bigsum
        lastadd=math.ceil(left/maxSwing)
        print(lastadd+len(biggerlist))

Solution (Python):
from bisect import bisect

N, H = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]

A, B = zip(*AB)
B = sorted(B)

max_A = max(A)
knifes = B[bisect(B, max_A):]

count = 0
while H > 0 and knifes:
    H -= knifes.pop()
    count += 1
if H > 0:
    count += -(-H//max_A)

print(count)

Solution (Python):
import sys
import os
import math
from operator import itemgetter
 
N, H  = map(int,input().split())
katana = [0 for _ in range(N)]
 
for i in range(N):
    a,b = map(int,input().split())
    katana[i] = [a,b]
katana = sorted(katana,key=itemgetter(1),reverse=True)
maxA = 0
for i in range(N):
    maxA = max(maxA,katana[i][0])
 
cnt = 0
for k in katana:
    if H <= 0:
        print(cnt)
        sys.exit()
    if k[1] > maxA:
        H -= k[1]
        cnt += 1
cnt += math.ceil(H/maxA)
print(cnt)

Solution (Python):
from operator import itemgetter
N,H = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]
MAX = 0
for i in AB:
  MAX = max(MAX,i[0])
AB.sort(key=itemgetter(1),reverse = True)
cnt = 0
for i in range(N):
  if AB[i][1] > MAX:
    H -= AB[i][1]
    cnt += 1
  if H <= 0:
    break
if H > 0:
  if H % MAX == 0:
    cnt += H // MAX
  else:
    cnt += H // MAX + 1
print(cnt)

Solution (Python):
import heapq

n, h = [ int(v) for v in input().split() ]
sword_list = []
for i in range(n):
    a, b = [ int(v) for v in input().split() ]
    sword_list.append((-a,1))
    sword_list.append((-b,0))
heapq.heapify(sword_list)

turn = 0
while h > 0:
    d = heapq.heappop(sword_list)
    if d[1] == 0:
        h += d[0]
        turn += 1
    else:
        attack_turn = (( h - d[0]- 1 ) // (-d[0]))
        h += d[0] * attack_turn
        turn += attack_turn
print(turn)

Solution (Python):
import heapq

N,HP = map(int,input().split())
Katana = [list(map(int,input().split())) for i in range(N)]

Wield,Throw = map(list,zip(*Katana))

Throw = list(map(lambda t:(-t,t),Throw))
heapq.heapify(Throw)

MaxW = max(Wield)

count = 0
while Throw:
  MaxT = heapq.heappop(Throw)[1]
  if MaxT >= MaxW:
    HP -= MaxT
    count += 1
    if HP <= 0:
      print(count)
      exit()

print(-(-HP//MaxW)+count)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+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)

t = B[:]
t.sort(reverse=True)

count = 0
for i in range(N):
    
    
    if t[i] >= max_a:
        H -= t[i]
        count += 1

    if H <= 0:
        print(count)
        exit()



x = (H // max_a) - 1
H -= (max_a * x)
count += x

while H > 0:
    H -= max_a
    count += 1


print(count)

Solution (Python):
def slove():
    import sys
    import heapq
    input = sys.stdin.readline
    n, h = list(map(int, input().rstrip('\n').split()))
    m_k = 0
    t = []
    heapq.heapify(t)
    for i in range(n):
        a, b = list(map(int, input().rstrip('\n').split()))
        m_k = max(m_k, a)
        heapq.heappush(t, -b)
    cnt = 0
    while True:
        if len(t) != 0:
            p = heapq.heappop(t)
            if m_k < -p:
                h += p
                cnt += 1
                if h <= 0:
                    print(cnt)
                    exit()
            else:
                break
        else:
            break
    print((h + m_k - 1) // m_k + cnt)


if __name__ == '__main__':
    slove()

Solution (Python):
N,H=map(int,input().split())
S=[[int(x) for x in input().split()] for _ in range(N)]
A,B=zip(*S)
A=max(A)
B=[b for b in B if b>A]
B.sort(reverse=True)
ans=0
cnt=0
for b in B:
    if H<=0:
        break
    cnt+=1
    H-=b
if H>0:
    cnt+=(H-1)//A+1
print(cnt)

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

Solution (Python):
from operator import itemgetter
import math



N,H = map(int,input().split())
sord = []
max_a = 0
for i in range(N):
 a,b = map(int,input().split())
 max_a = max(max_a,a)
 sord.append([a,b])
sord = sorted(sord, key=itemgetter(1) , reverse = True)

count = 0
for i in range(N):
  if(sord[i][1] >= max_a):
   
   H = H - sord[i][1]
   count += 1
   if(H <= 0):
    H = 0
    break


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

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

A = []
A_append = A.append
B = []
B_append = B.append
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
b = 0
while b < N and B[b] > A[0] and H > 0:
    count += 1
    H -= B[b]
    b += 1
if H > 0:
    count += (H + A[0] - 1) // A[0]
print (count)

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

def main():
    
    n,h = map(int,input().split())
    a,b = [0 for _ in range(n)],[0 for _ in range(n)]
    for i in range(n):
        a[i],b[i] = map(int,input().split())
    b.sort(reverse=True)
    max_a = max(a)
    
    

    
    ans = 0
    for i in range(n):
        if b[i]>=max_a:
            h -= b[i]
            ans += 1
        if h<=0:
            print(ans)
            exit()
    ans += ceil(h/max_a)
    print(ans)
    
if __name__ == "__main__":

    main()

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

Solution (Python):


 
N,H = map(int,input().split())
AB = [[int(x) for x in input().split()] for _ in range(N)]
A,B = zip(*AB)
 
a = max(A) 
B = [b for b in B if b > a] 
B.sort(reverse = True)

attack_cnt = 0
 
for b in B:
  if H <= 0:
    break
  attack_cnt += 1
  H -= b
  
if H > 0:
  attack_cnt += (H-1)//a + 1
  
print(attack_cnt)

Solution (Python):
from math import ceil

N, H = map(int, input().split())
sword = [[int(x) for x in input().split()] for _ in range(N)]

max_swing = max(sword, key=lambda x:x[0])[0]

attack = 0

for i in sorted(sword, key=lambda x: x[1], reverse=True):
  if max_swing < i[1]:
    H -= i[1]
    attack += 1
    if H <= 0:
      break

if 0 < H:
  attack += ceil(H / max_swing)
print(attack)