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

Solution (Python):
n, h = map(int, input().split())
a = [None for _ in range(n)]
b = [None for _ in range(n)]
ans = 0
for i in range(n):
    a[i], b[i] = map(int, input().split())
a_s = sorted(a)[::-1]
b_s = sorted(b)[::-1]
for i in range(n):
    if b_s[i] >= a_s[0]:
        h -= b_s[i]
        ans += 1
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += (h + a_s[0] - 1) // a_s[0]
print(ans)

Solution (Python):
from math import ceil

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

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

B.sort(reverse=True)

ans = 0
for b in B:

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

    if b > max_A:
        H -= b
        ans += 1
    else:
        break

print(ans + ceil(H / max_A))

Solution (Python):
from math import ceil

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 = sorted(list(filter(lambda x: x > max_a, B)))

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

Solution (Python):
from math import ceil
N,H = map(int,input().split())
katana = []
for i in range(N):
    a,b = map(int,input().split())
    katana.append((a,'a'))
    katana.append((b,'b'))
katana.sort()
katana.reverse()
damage = 0
ans = 0
i = 0
while damage < H:
    if katana[i][1] == 'b':
        ans += 1
        damage += katana[i][0]
        i += 1
    else:
        ans += ceil((H-damage)/katana[i][0])
        break

print(ans)

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)
amax = max(A)

B = list(filter(lambda x: x > amax, B))
B.sort()
ans = 0
while H > 0:
    
    if B:
        H -= B.pop()
    
    else:
        ans += math.ceil(H/amax)
        break
    ans += 1
print(ans)

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


 
max_a = np.max(ab[:,0])
b_sort = np.sort(ab[:,1])[::-1] 
 
ans = 0
 
b_sort = b_sort[np.where(b_sort > max_a)]
 

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

if H % max_a == 0:
  ans += H // max_a
else:
  ans += H // max_a + 1
 
print(ans)

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

sw_max = 0
for i in range(n):
    if katana[i][0] > sw_max:
        sw_max = katana[i][0]

count = 0
katana.sort(key=lambda x: x[1], reverse=True)
for i in range(n):
    if katana[i][1] > sw_max:
        h -= katana[i][1]
        count += 1
    if h <= 0:
        print(count)
        exit()

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

Solution (Python):
import bisect

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

AB.sort()
MAX=AB[N-1][0]

AB.sort(key=lambda x:x[1])

for i in range(N):
    if AB[i][1]>MAX:
        break

THRSUM=[AB[N-1][1]]
for j in range(N-2,i-1,-1):
    THRSUM.append(AB[j][1]+THRSUM[-1])

if H>THRSUM[-1]:
    ANS=0
    H-=THRSUM[-1]
    ANS+=len(THRSUM)

    print(ANS+-(-H//MAX))

else:
    print(bisect.bisect_left(THRSUM,H)+1)

Solution (Python):
import bisect
import sys

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

AB.sort()
MAX=AB[N-1][0]

AB.sort(key=lambda x:x[1])

if AB[N-1][1]<=MAX:
    print(-(-H//MAX))
    sys.exit()


for i in range(N):
    if AB[i][1]>MAX:
        break

THRSUM=[AB[N-1][1]]
for j in range(N-2,i-1,-1):
    THRSUM.append(AB[j][1]+THRSUM[-1])

if H>=THRSUM[-1]:
    ANS=0
    H-=THRSUM[-1]
    ANS+=len(THRSUM)

    print(ANS+(-(-H//MAX)))

else:
    
    for i in range(len(THRSUM)):
        
        if H<=THRSUM[i]:
            
            print(i+1)
            break

Solution (Python):
N,H = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(N)]
maxa = 0
bs = []
for a,b in src:
    maxa = max(maxa, a)
    bs.append(b)
bs.sort()

ans = 0
while bs:
    b = bs.pop()
    if b <= maxa: break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

ans += -(-H//maxa)
print(ans)

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

sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,h = li()
alis = []
blis = []
for _ in range(n):
    a,b = li()
    alis.append(a)
    blis.append(b)
    
amax = max(alis)
blis.sort()
buse = []
while blis:
    cur = blis.pop()
    if cur > amax:
        buse.append(cur)
    
cnt = 0
res = h
for b in buse:
    res -= b
    cnt += 1
    if res <= 0:
        break
    
if res > 0:
    cnt += -(-res//amax)
    
print(cnt)

Solution (Python):
from operator import attrgetter


class Damage:
    def __init__(self, a, b):
        self.a = a
        self.b = b


N, H = map(int, input().split())
damages = []
for _ in range(N):
    a, b = map(int, input().split())
    damages.append(Damage(a, b))
damages = sorted(damages, key=attrgetter("b"), reverse=True)

max_a_damage = (max(damages, key=lambda damage: damage.a)).a
cnt = 0
sum = 0
for damage in damages:
    if damage.b <= max_a_damage:
        cnt += int((H-sum) / max_a_damage)
        if (H-sum) % max_a_damage > 0:
            cnt += 1
        sum = H
        break
    else:
        cnt += 1
        sum += damage.b
        if H <= sum:
            break
if H-sum > 0:
    cnt += int((H-sum) / max_a_damage)
    if (H-sum) % max_a_damage > 0:
        cnt += 1

print(cnt)

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

t = 0
c = []
M = max(x[i][0] for i in range(n))

for i in range(n):
	if x[i][1]>M-1:
		c.append(x[i][1])
c.sort()
c.reverse()

if sum(c)>h-1:
	for i in range(len(c)):
		t += 1
		h -= c[i]
		if h<1:
			print(t)
			break
else:
	h -=sum(c)
	q = (h-1)//M+1
	print(q+len(c))

Solution (Python):
def main():

    S = list(input())
    checklist = [0 for i in range(26)]
    for i in S:
        checklist[ord(i) - ord("a")] += 1
    ans = True

    for i in checklist:
        if i > 1:
            ans = False

    if not ans:
        print(-1)
        return 0
    else:
        ans = False
        for i in range(len(checklist)):
            if checklist[i] == 0:
                for i in S:
                    print(i, end="")
                print(chr(i + ord("a")), end = "")
                print()
                ans = True
                break

        if not ans:
            new_S = []
            for i in S:
                new_S.append(ord(i))

            for i in range(len(new_S) - 1):
                if new_S[i] > new_S[i + 1]:
                    for j in range(i - 1):
                        print(S[j], end = "")
                    print(chr(new_S[i - 1] + 1), end = "")
                    print()
                    ans = True
                    break

            if not ans:
                print(-1)


def ABC069D():

    H, W = map(int, input().split())
    N = int(input())
    a = list(map(int, input().split()))
    ans = []
    for i in range(N):
        for j in range(a[i]):
            ans.append(i + 1)
    printlist = [[0 for i in range(W)] for j in range(H)]
    k = 0
    for i in range(H):
        for j in range(W):
            printlist[i][j] = ans[k]
            k += 1
        if i % 2 != 0:
            printlist[i] = printlist[i][::-1]

    for i in range(H):
        for j in range(W):
            print(printlist[i][j], end = "")
            if j != W:
                print(" ", end = "")
        print()
    print()


import math
def cc(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def ABC057D():

    N, A, B = map(int, input().split())
    v = list(map(int, input().split()))
    v = sorted(v)[::-1]

    anslist = []
    for i in range(A, B + 1):

        anslist.append([sum(v[0:i]) / i, i, v[i - 1]])
    anslist.sort()
    anslist = anslist[::-1]
    ans = anslist[0][0]
    key = anslist[0][2]
    long = anslist[0][1]
    print(ans)
    for i in range(1, len(anslist)):
        if anslist[i][0] == anslist[i - 1][0]:
            ans = anslist[i][0]
            key = anslist[i][2]
            long = anslist[i][1]
        else:
            break
    
    
    cnt = 0
    for i in v:
        if i == key:
            cnt += 1

    c = 0
    for i in v[:long]:
        
        if i == key:
            c += 1
    
    ans = 0
    if c == long:
        for i in range(A,  min(B + 1, cnt + 1)):
            ans += cc(cnt, i)
    else:
        ans = cc(cnt, c)
    
    
    print(ans)


def ABC104D():
    S = list(input())
    A_cnt = 0
    B_cnt = 0
    C_cnt = 0
    Q_cnt = 0
    ans = 0
    for i in S:
        if i == "A":
            A_cnt += 1
        elif i == "B":
            B_cnt += 1
        elif i == "C":
            C_cnt += 1
        else:
            Q_cnt += 1
    for i in range(Q_cnt + 1):
        for j in range(Q_cnt - i + 1):
            k = Q_cnt - i - j
            if A_cnt + i > 0 and B_cnt + j > 0 and C_cnt + k > 0:
                f_i = math.factorial(i)
                f_j = math.factorial(j)
                f_k = math.factorial(k)
                if f_i == 0:
                    f_i = 1
                if f_j == 0:
                    f_j = 1
                if f_k == 0:
                    f_k = 1
                ans += (A_cnt + i) * (B_cnt + j) * (C_cnt + k) * math.factorial(Q_cnt) // f_i // f_j // f_k
                print(ans, i, j, k, A_cnt + i, B_cnt + j, C_cnt + k)
                print(math.factorial(Q_cnt), f_i, f_j, f_k)
    print(ans)


def ARC073D():
    N, W = map(int, input().split())
    wv = [list(map(int, input().split())) for i in range(N)]

def ARC075():
    N, A, B = map(int, input().split())
    h = [int(input()) for i in range(N)]
    def enogth(T):
        import copy
        this_h = copy.copy(h)
        cnt = 0
        for i in range(N):
            this_h[i] -= B
            key = 0
            if this_h[i] > 0:
                key = this_h[i] / (A - B)
                if int(key) != key:
                    key += 1
                cnt += int(key)
        if cnt <= T:
            return True
        else:
            return False
    def sarch(i: object) -> object:
        print(i)
        if enogth(i):
            if i // 2 == 1:
                return i
            sarch(0 + i // 2)
        else:
            sarch(i + i // 2)
    print(sarch(10 ** 9))


def ARC082D():
    N = int(input())
    p = list(map(int, input().split()))
    cnt = 0
    if p[N - 1] == N:
        
        p[-2], p[-1] = p[-1], p[-2]
        cnt += 1

    for i in range(N - 1):
        if p[i] == i + 1:
            p[i], p[i + 1] = p[i + 1], p[i]
            cnt += 1
    print(cnt)


from queue import Queue
def ABC070D():
    N = int(input())
    a, b, c =map(int, input().split())
    Q, K = map(int, input().split())
    xy = [list(map(int, input().split())) for i in range(Q)]
    x = [[] for i in range(N)]
    for i, j in xy:
        x[i - 1].append(j - 1)
        x[j - 1].append(i - 1)

    q = Queue()
    visited = [0 for i in range(N)]

def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    v = list(map(int, input().split()))
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    print(speed_lim)
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 1
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    print(speed_list)
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 1, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    print(speed_list)
    ans = 0
    for i in speed_list:
        ans += i

    print(ans)


def ABC076D():
    N = int(input())
    t = list(map(int, input().split()))
    a = []
    for i in t:
        a.append(i * 2)
    t = a
    v = list(map(int, input().split()))
    
    speed_lim = [0]
    speed_list = [0 for i in range(sum(t) + 1)]
    for i in range(N):
        for j in range(t[i]):
            speed_lim.append(v[i])
    
    for i in range(1, sum(t) + 1):
        speed_list[i] = speed_list[i - 1] + 0.5
        if speed_list[i] > speed_lim[i]:
            speed_list[i] = speed_lim[i]
    
    speed_list[-1] = 0
    for i in range(sum(t) - 1, -1, -1):
        speed_list[i] = min(speed_list[i + 1] + 0.5, speed_list[i])
        if speed_list[i] > speed_lim[i + 1]:
            speed_list[i] = speed_lim[i + 1]
    
    ans = 0
    for i in speed_list:
        ans += i

    print(ans / 2)


def ABC085D():
    N, H = map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(N)]
    a = []
    b = []
    for i, j in ab:
        a.append(i)
        b.append(j)
    a.sort()
    b.sort()
    a = a[::-1]
    b = b[::-1]
    damage = 0
    cnt = 0
    for i in b:
        if i < a[0]:
            break
        damage += i
        cnt += 1
        if damage >= H:
            break
    key = 0
    if damage < H:
        key = (H - damage) / a[0]
        if int(key) != key:
            key += 1
        key = int(key)

    cnt += key

    print(cnt)
ABC085D()

Solution (Python):
n,h = map(int, input().split())
list_ken = []
for i in range(n):
    list_ken.append(list(map(int, input().split())))
max_kiri = 0
for i in range(n):
    if max_kiri < list_ken[i][0]:
        max_kiri = list_ken[i][0]
sum_nage = 0
count_nage = 0
list_nage = []
for i in range(n):
    if list_ken[i][1] >= max_kiri:
        sum_nage += list_ken[i][1]
        list_nage.append(list_ken[i][1])
        count_nage += 1

list_nage.sort(reverse = True)

if (h - sum_nage) < 0:
    i = 0
    while h > 0:
        h -= list_nage[i]
        i += 1
    print(i)

elif (h - sum_nage) % max_kiri == 0:
    print((h-sum_nage) // max_kiri + count_nage)
else:
    print((h-sum_nage)//max_kiri + 1 + count_nage)

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

Solution (Python):
import bisect

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 = sorted(b)
nage = b[bisect.bisect_right(b, max(a)):]
ans = 0
for i in nage[::-1]:
    h -= i
    ans += 1
    if h <= 0:
        break
ans += max(-(-h // max(a)), 0)
print(ans)

Solution (Python):
import math

n, h = list(map(int, input().split()))
a, b = [], []
for _ in range(n):
    a_i, b_i = list(map(int, input().split()))
    a.append([a_i, 'a'])
    b.append([b_i, 'b'])
damages = sorted(a+b, reverse = True)

ans = 0
for d, is_ab in damages:
    if is_ab == 'a':
        ans += math.ceil(h/d)
        break
    else:
        h -= d
        ans += 1
        if h <= 0:
            break

print(ans)

Solution (Python):
N,HP=map(int,input().split())
K=0
listN=[]
 
for i in range(N):
    k,n=map(int,input().split())
    if k>K:
        K=k
    listN.append(n)
listN.sort(reverse=True)
cnt=0
for i in range(N):
    if listN[i]>=K:
        HP-=listN[i]
        cnt+=1
        if HP<=0:
            print(cnt)
            exit()
    else:
        break
 
cnt+=int((HP+K-1)/K)
print(cnt)

Solution (Python):
n,h=map(int,input().split())
slash=[]
throw=[]
for i in range(n):
    x,y=map(int,input().split())
    slash.append(x)
    throw.append(y)
 
slash.sort(reverse=True)
throw.sort(reverse=True)
attack=0
for i in range(n):
    if throw[i]>=slash[0]:
        h-=throw[i]
        attack+=1
        if h<=0:
            print(attack)
            exit()
    else :
        break
 
attack+=int((h+slash[0]-1)/(slash[0]))
print(attack)

Solution (Python):
import math

n, h = map(int, input().split())
ba = [tuple(map(int, reversed(input().split()))) for i in range(n)]
ba.sort(reverse = True)

ans = 2000000000

bs = [0]
for i in range(n):
    bs.append(bs[i] + ba[i][0])
    if bs[i + 1] >= h:
        ans = min(ans, i + 1)


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

    L = i
    R = n
    while (R - L > 1):
        M = (L + R) // 2
        if ba[M][0] < a:
            R = M
        else:
            L = M
    if h - bs[R] < 0:
        continue
    ans = min(ans, R + math.ceil((h - bs[R]) / a))

print(ans)

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.sort(reverse=True)
B.sort(reverse=True)
i,p = 0,0
while i<N and A[0]<=B[i] and p<H:
    p += B[i]
    i += 1
ans = math.ceil((H-p)/A[0]) if p<H else 0
print(ans+i)

Solution (Python):
f = lambda: map(int, input().split())
n,h = f()
mA,B = 0,[]
for _ in range(n):
    a,b = f()
    mA = max(mA,a)
    B.append(b)
B = sorted([i for i in B if i > mA], reverse=True)
ans = 0
while h>0:
    if not B:
        ans += -(-h//mA)
        break
    else:
        h -= B[0]
        B.pop(0)
        ans += 1
print(ans)

Solution (Python):
n,h=map(int,input().split())
slash=[]
throw=[]
for i in range(n):
    x,y=map(int,input().split())
    slash.append(x)
    throw.append(y)

slash.sort(reverse=True)
throw.sort(reverse=True)
attack=0
for i in range(n):
    if throw[i]>=slash[0]:
        h-=throw[i]
        attack+=1
        if h<=0:
            print(attack)
            exit()
    else :
        break

attack+=int((h+slash[0]-1)/(slash[0]))
print(attack)

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

Solution (Python):
import numpy as np
import math
N, H = map(int, input().split())
a, b = [0]*N, [0]*N
max_a = 0
diff, diff_idx, diff_a, diff_b = np.float('inf'), -1, -1, -1
for i in range(N):
    a[i], b[i] = map(int, input().split())
    max_a = max(a[i], max_a)
count = 0
damage = 0
for bi in sorted(b, reverse=True):
    if bi < max_a:
        break
    damage += bi
    count += 1
    if damage >= H:
        print(count)
        exit()

count += math.ceil((H - damage) / max_a)

print(count)

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

N, H = map(int, input().split())
max_a = 0
b = [0] * N
for i in range(N):
    a, b[i] = map(int, input().split())
    max_a = max(max_a, a)
b.sort(reverse=True)

cnt = 0
for bi in b:
    if bi < max_a:
        break
    H -= bi
    cnt += 1
    if H <= 0:
        break

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

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

max_a = max(a)
b = [x for x in sorted(b, reverse=True) if x > max_a]

cnt = 0
for bi in b:
    H -= bi
    cnt += 1
    if H <= 0:
        break

if H > 0:
    cnt += H // max_a
    if H % max_a != 0:
        cnt += 1

print(cnt)

Solution (Python):
n,h=map(int,input().split())
l=[tuple(map(int,input().split())) for _ in range(n)]
th=max(l,key=lambda x:x[0])[0]
l=sorted([i for i in l if i[1]>=th],key=lambda x:-x[1])
c,v=0,0
for i in l:
  if v<h:
    v+=i[1]
    c+=1
if v<h:
  a,b=divmod(h-v,th)
  if b:a+=1
  c+=a
print(c)

Solution (Python):

import bisect, math
N, H = map(int, input().split())
a = []
b = []
for k in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)

a = sorted(a)
b = sorted(b)

l = N - bisect.bisect_left(b,a[-1])
b = b[::-1]
ans = 0
for k in range(l):
    ans += 1
    H -= b[k]
    if H <= 0:
        print(ans)
        exit(0)

print(ans + math.ceil(H/a[-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)
    
a_max = max(a)
b.sort(reverse = True)

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

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

count = 0
biga = max(a)
bigb = max(b)
b.sort(reverse = True)

while H > 0:
    if bigb > biga:
        count += 1
        H -= bigb
        b.remove(bigb)
        bigb = b[0]        
    else:
        count += H//biga
        H -= (H//biga)*(biga)
        if H != 0:
            count += 1
        break
        

print(count)

Solution (Python):


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def solve(N, H, A, B):
    a_max = max(A)
    ans = 0
    for b in sorted(B, reverse=True):
        if H <= 0:
            break

        if b > a_max:
            H -= b
            ans += 1
        else:
            break
    if H > 0:
        ans += ceil(H, a_max)
    return ans


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

    print(solve(N, H, A, B))


if __name__ == '__main__':
    main()

Solution (Python):
from math import ceil
N, H = map(int, input().split())
B = []
maxa = 0
cnt = 0

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

B.sort(reverse=True)

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

cnt += ceil(H / maxa)

print(cnt)

Solution (Python):
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)
count = 0
a = max(a_list)
b_list.sort()
while len(b_list) >= 1 and H >= 1:
    if b_list[-1] >= a:
        b = b_list.pop(-1)
        H -= b
        count += 1
    else:
        break
if H <= 0:
    print(count)
else:
    tmp = H // a if H % a == 0 else H //a + 1
    print(count + tmp)

Solution (Python):
from itertools import accumulate
from bisect import bisect_left
from math import ceil

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_max = max(A)


b_strong = []
for b in B:
    if b >= a_max:
        b_strong.append(b)
        

b_strong.sort(reverse=True)
b_cum = list(accumulate(b_strong))
b_cum = [0] + b_cum
    

if H <= b_cum[-1]:
    ans = bisect_left(b_cum, H)
    
else:
    ans = len(b_cum) - 1
    ans += ceil((H - b_cum[-1]) / a_max)
    
print(ans)

Solution (Python):
from itertools import accumulate
from bisect import bisect_left
from math import ceil

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


AB.sort(key=lambda x: (x[0], -x[1]))


equip = AB.pop()


b_list = []
for a,b in AB:
    if b > equip[0]:
        b_list.append(b)


b_list.sort(reverse=True)
b_list_cum = list(accumulate(b_list))
b_list_cum = [0] + b_list_cum
 
ans = 0

if H <= b_list_cum[-1]:
    ans = bisect_left(b_list_cum,H)
    print(ans)



else:
    ans = len(b_list_cum)-1
    res = H - b_list_cum[-1]
    a_attack = max(0, int(ceil((res-equip[1]) / equip[0])))
    
    
    ans += (a_attack + 1)
    print(ans)

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

a = [0 for _ in range(n)]
b = [0 for _ in range(n)]
s = [[] for _ in range(n)]
for i in range(n):
    s[i] =list(map(int, input().split()))

temp = s[0][0]
for i in range(1, n):
    temp = max(s[i][0], temp)

b = []
for x in s:
    if x[1] > temp:
        b.append(x[1])

b = list(reversed(sorted(b)))

d = 0
ans = 0
while d < h and len(b) > 0:
    d += b[0]
    b.pop(0)
    ans += 1

if d < h:
    ans += (h - d) // temp
    if (h - d) % temp != 0:
        ans += 1

print(ans)

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(10000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]




dp = None


def main():
    N, H = li_input()
    S = [li_input() for _ in range(N)]

    ans = 0
    strong_throw = []

    maxcut = -1
    for s in S:
        if s[0] > maxcut:
            maxcut = s[0]

    for s in S:
        if s[1] > maxcut:
            strong_throw.append(s[1])

    strong_throw.sort(reverse=True)

    for st in strong_throw:
        H -= st
        ans += 1

        if H <= 0:
            break

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

    print(ans)


main()

Solution (Python):
import bisect
n,h = map(int,input().split())
v=[list(map(int,input().split())) for i in range(n)]

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

a = []
b = []
for i in range(n):
    a.append(v[i][0])
    b.append(v[i][1])

m = max(a)    
k = bisect.bisect_left(b,m)
b.append(0)




hj = (h-sum(b[k::]))
if hj%m == 0:
    i = 0
else:
    i = 1

if hj <= 0:
    for i in range(n):
        h  = h-b[n-1-i]
        if h <= 0:
            print(i + 1)
            break
else:
    print(hj//m + i + n - k)

Solution (Python):
N, H = map(int, input().split())
swords = sorted([tuple(map(int, input().split())) for _ in range(N)],
                key=lambda x: -x[1])
max_a = max(swords, key=lambda x: x[0])[0]
cnt = 0
for a, b in swords:
    if b > max_a:
        cnt += 1
        H -= b
    if H <= 0:
        print(cnt)
        break
else:
    print(cnt + -(-H // max_a))

Solution (Python):
N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
B.sort()
B.reverse()
i = 0
Mb = B[0]
while Mb > Ma and H > 0:
  i += 1
  H -= Mb
  if i == N:
    Mb = 0
  else:
    Mb = B[i]
if H <= 0:
  print(i)
else:
  print(i+int(-(-H//Ma)))

Solution (Python):


def solve():
    n, m = map(int, input().split())
    
    
    swing, throw = [], []
    for _ in range(n):
        a, b = map(int, input().split())
        swing.append(a)
        throw.append(b)
    swing = sorted(swing)
    throw = sorted(throw)
    max_swing = swing[-1]
    will_throw = [x for x in throw if x > max_swing]

    all_damage = sum(will_throw)
    answer = len(will_throw)
    if all_damage > m:
        for damage in will_throw:
            if all_damage - damage < m:
                print(answer)
                return
            else:
                all_damage -= damage
                answer -= 1
    else:
        print(answer + ((m - all_damage) + (max_swing - 1)) // max_swing)
        return

solve()

Solution (Python):
import math

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

hit = 0
throw = []
for i in range(N):
    h, t = map(int, input().split())
    if h > hit:
        hit = h
    throw.append(t)

throw.sort()

ans = 0
for t in throw[::-1]:
    if t < hit:
        break
    else:
        ans += 1
        HP -= t
        if HP <= 0:
            break
if HP > 0:
    ans += HP // hit
    if HP % hit != 0:
        ans += 1

print(ans)

Solution (Python):
import math

N, H = map(int, input().split())
a = []
b = []

for i in range(N):
    x, y = map(int, input().split())
    a.append(x)
    b.append(y)
max_a = max(a)
b = [i for i in b if i >= max_a]
b.sort()
b.reverse()
count = 0
for i in b:
    H -= i
    count +=1
    if H <= 0:
        print(count)
        quit()
print(math.ceil(H /max_a)+count)