qyliang/CodeNanoFix huggingface dataset:
Buggy code:
#!/usr/bin/env python3
import bisect
import sys
import math
sys.setrecursionlimit(10**6)


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

a = []
b = []
ab = []
for i in range(n):
    a_tmp, b_tmp = list(map(int, input().split()))
    a.append(a_tmp)
    b.append(b_tmp)
    # ab.append((b_tmp, a_tmp))

a_max = max(a)
b.sort()

index = bisect.bisect_right(b, a_max)

ans = 0
for i in reversed(range(index, n)):
    h -= b[i]
    ans += 1
    if h <= 0:
        break

if h > 0:
    ans += math.floor(h/a_max)

print(ans)


Fixed code:
#!/usr/bin/env python3
import bisect
import sys
import math
sys.setrecursionlimit(10**6)


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

a = []
b = []
ab = []
for i in range(n):
    a_tmp, b_tmp = list(map(int, input().split()))
    a.append(a_tmp)
    b.append(b_tmp)
    # ab.append((b_tmp, a_tmp))

a_max = max(a)
b.sort()

index = bisect.bisect_right(b, a_max)

ans = 0
for i in reversed(range(index, n)):
    h -= b[i]
    ans += 1
    if h <= 0:
        break

# print(h)
if h > 0:
    ans += math.ceil(h/a_max)

print(ans)
Buggy code:
n,h = map(int,input().split())
al=[]
bl=[]
for _ in [0]*n:
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()
ans = 0
while h>0:
  if bl[-1]>al[-1]:
    h-=bl[-1]
    ans+=1
    del bl[-1]
  else:
    ans += -(-h//al[-1])
    h=0
print(ans)

Fixed code:
n,h = map(int,input().split())
al=[]
bl=[]
for _ in [0]*n:
  a,b = map(int,input().split())
  al.append(a)
  bl.append(b)
al.sort()
bl.sort()
ans = 0
while h>0:
  if len(bl)>0 and bl[-1]>al[-1]:
    h-=bl[-1]
    ans+=1
    del bl[-1]
  else:
    ans += -(-h//al[-1])
    h=0
print(ans)
Buggy code:
n,h = (int(i) for i in input().split())
A,B = [],[]
for _ in range(n):
    a,b = [int(i) for i in input().split()]
    A.append(a)
    B.append(b)
a_max = max(A)
B.sort()[::-1]
power,ans = 0,0
for b in B:
    if a_max <= b:
        power += b
        ans += 1
        if power>=h: break
if power>=h:
    print(ans)
else:
    h -= power
    ans += h//a_max
    if h%a_max == 0: print(ans)
    else: print(ans+1)


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

shake = max(a)
b.sort(reverse=True)
ans = 0
if sum(b) < H:
    ans += (H-sum(b))//shake
    ans += 1
    H -= ans * shake
i=0
while H>0:
    ans += 1
    H -= b[i]
    i += 1

print(ans)

Fixed code:
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)

shake = max(a)
throw = 0
for i in b:
    if i > shake:
        throw += i

b.sort(reverse=True)

ans = 0
if throw < H:
    ans += (H-throw+shake-1)//shake
    H -= ans * shake

i=0
while H>0:
    ans += 1
    H -= b[i]
    i += 1


print(ans)
Buggy code:
N,H=map(int,input().split())
sl=[]
th=[]
for i in range(N):
  s,t=map(int,input().split())
  sl.append(s)
  th.append(t)

gsl=max(sl)
ans=0
while H>0:
  if gsl<max(th):
    at=max(th)
    H-=at
    ans+=1
    th.remove(at)
  else:
    ans+=H//gsl
    if H%gsl!=0:
      ans+=1
    break
print(ans)

Fixed code:
N,H=map(int,input().split())
sl=[]
th=[]
for i in range(N):
  s,t=map(int,input().split())
  sl.append(s)
  th.append(t)
th.sort()
gsl=max(sl)
ans=0
while th:
  if gsl<th[-1]:
    at=th.pop(-1)
    H-=at
    ans+=1
    if H<=0:
      break
  else:
    ans+=H//gsl
    if H%gsl!=0:
      ans+=1
    break
else:
  ans+=H//gsl
  if H%gsl!=0:
    ans+=1
print(ans)
Buggy code:
N,H = list(map(int, input().split()))
A=0
B=[]
for _ in range(N):
    a,b = list(map(int, input().split()))
    A = max(A, a)
    B.append(b)

B.sort(reverse=True)
from itertools import accumulate
B = list(accumulate(B))
HP_after_throw = H - B[-1]
print(HP_after_throw)
if HP_after_throw <= 0:
    for i,b in enumerate(B,1):
        if H<b:
            print(i)
            exit()
    raise AssertionError('error')
else:
    q,r = divmod(HP_after_throw, A)
    print(N+q+min(1, r))


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

B = sorted([b for b in B if b>A], reverse=True)
from itertools import accumulate
B = list(accumulate(B))
total_throw_damage = (B[-1] if len(B)>0 else 0)

HP_after_throw = H - total_throw_damage
if HP_after_throw <= 0:
    for i,b in enumerate(B,1):
        if H<=b:
            print(i)
            exit()
    raise AssertionError('error')
else:
    q,r = divmod(HP_after_throw, A)
    print(len(B)+q+min(1, r))
Buggy code:
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)
else:
    print(H//A + ans)


Fixed code:
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)
Buggy code:
def main():
    N, H = map(int, input().split())

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

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

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

    print(ans)

main()

Fixed code:
def main():
    N, H = map(int, input().split())

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

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

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

    print(ans)

main()
Buggy code:
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()) 
ma = max(a)
count=0
for bi in sorted(b, reverse=True):
    if bi<ma:
        break
    count += 1
    H -= bi
    if H<=0:
        break
if H > 0:
    count += (H+1)//ma
print(count)



Fixed code:
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()) 
ma = max(a)
count=0
for bi in sorted(b, reverse=True):
    if bi<ma:
        break
    count += 1
    H -= bi
    if H<=0:
        break
if H > 0:
    if H%ma == 0:
        count += H//ma
    else:
        count += H//ma +1
print(count)
Buggy code:
import math

N, H = map(int, input().split())
kiri = []
nage = []
for n in range(N):
    tmps = list(map(int, input().split()))
    kiri.append(tmps[0])
    nage.append(tmps[1])

kiri_max = max(kiri)
nage.sort(reverse=True)

count = 0
while (H > 0):
    if (len(nage) != 0):
        H -= nage[0]
        nage.pop(0)
        count += 1
    else:
        if ( H % kiri_max):
            count += H // kiri_max
        else:
            count += H // kiri_max + 1
        break

print(count)

Fixed code:
import math

N, H = map(int, input().split())
kiri = []
nage = []
for n in range(N):
    tmps = list(map(int, input().split()))
    kiri.append(tmps[0])
    nage.append(tmps[1])

kiri_max = max(kiri)
nage.sort(reverse=True)
nage = list(filter(lambda x: x >= kiri_max, nage))

count = 0
while (H > 0):
    if (len(nage) != 0):
        H -= nage[0]
        nage.pop(0)
        count += 1
    else:
        if ( H % kiri_max == 0):
            count += H // kiri_max
        else:
            count += H // kiri_max + 1
        break

print(count)
Buggy code:
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=max(A)
B.sort(reverse=True)
count=0
for i in B:
  if A>i:
    break
  else:
    h-=i
    count+=1
print(count+h//A)

Fixed code:
n,h = map(int,input().split())
A = []
B = []
m = 0
for j in range(n):
    a,b = map(int,input().split())
    m = max(a,m)
    A.append(a)
    B.append(b)
B.sort(reverse=True)
for i in range(n):
    if B[i] > m:
        h -= B[i]
    else:
        print(i+1+(h-1)//m)
        break
    if h <= 0:
        print(i+1)
        break
else:
    print(n+1+(h-1)//m)
Buggy code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a_max=0
b=[]
ans=0
kaisuu=0
for i in range(n):
  if a_max<ab[i][0]:
    a_max=ab[i][0]
for i in range(n):
  b.append(ab[i][1])
b.sort(reverse=True)
for i in range(n):
  if a_max<b[i]:
    h-=b[i]
    kaisuu+=1
  else:
    if h%a_max==0:
      kaisuu+=(h//a_max)
    else:
      kaisuu+=((h//a_max)+1)
    break
print(kaisuu)  

Fixed code:
n,h=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]
a_max=0
b=[]
ans=0
kaisuu=0
for i in range(n):
  if a_max<ab[i][0]:
    a_max=ab[i][0]
for i in range(n):
  b.append(ab[i][1])
b.sort(reverse=True)
i=0
while True:
  if len(b)>i and a_max<b[i]:
    h-=b[i]
    kaisuu+=1
  else:
    if h%a_max==0:
      kaisuu+=(h//a_max)
    else:
      kaisuu+=((h//a_max)+1)
    break
  if h<=0:
    break
  i+=1
print(kaisuu)
Buggy code:
n,h=map(int, input().split())
w=[]
for i in range(n):
    a,b=map(int, input().split())
    w.append([a,b])
    
w.sort(key=lambda x:x[0],reverse=True)
m=w[0][0]
w.sort(key=lambda x:x[1],reverse=True)

count=0
for i in range(n):
    if w[i][1]>=m:
        count+=1
        h -= w[i][1]
        
    if h<=0:
        print(count)
        break
else:
    
    while h>0:
        h -= m
        count+=1
print(count)

Fixed code:
n,h=map(int, input().split())
w=[]
for i in range(n):
    a,b=map(int, input().split())
    w.append([a,b])
w.sort(key=lambda x:x[0],reverse=True)
m=w[0][0]
w.sort(key=lambda x:x[1],reverse=True)

count=0
for i in range(n):
    if w[i][1]>=m:
        count+=1
        h -= w[i][1]
        
    if h<=0:
        print(count)
        break
else:
    print(count+(h+m-1)//m)
Buggy code:
N, H = map(int, input().split())
#ab = [list(map(int, input().split())) for i in range(N)]
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
from bisect import bisect_left
end = bisect_left(b, max(a))
#H = 500
i = N - 1

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

Fixed code:
N, H = map(int, input().split())
#ab = [list(map(int, input().split())) for i in range(N)]
a = []
b = []
for i in range(N):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
a.sort()
b.sort()
from bisect import bisect_left
end = bisect_left(b, max(a))
#H = 500
i = N - 1
cnt = 0
while H > 0 and end <= i:
    #print(i)
    H -= b[i]
    cnt += 1
    i -= 1
if H <= 0:
    print(cnt)
    quit()
import math
print(math.ceil(H / max(a)) + cnt)
Buggy code:
import math
N,H = map(int,input().split())

aList = []
bList = []
for count in range(0,N):
    a,b = map(int, input().split())
    aList.append(a)
    bList.append(b)

bList.sort()
bList.reverse()

count = 0
damage = 0
for b in bList:
    damage+=b
    count+=1
    if damage > H:
        break

if damage < H:
    remainingHP = H - sum(bList)
    maxA = max(aList)
    count = count + math.floor(remainingHP / maxA)

print(count)

Fixed code:
import math
N,H = map(int,input().split())

aList = []
bList = []
for count in range(0,N):
    a,b = map(int, input().split())
    aList.append(a)
    bList.append(b)

bList.sort()
bList.reverse()

maxA = max(aList)

count = 0
damage = 0
for b in bList:
    if maxA < b:
        damage+=b
        count+=1
    if damage >= H:
        break

if damage < H:
    remainingHP = H - damage
    count = count + math.ceil(remainingHP / maxA)

print(count)
Buggy code:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()

hp = H
res = 0
for b in kb:
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + max(ka) - 1)//max(ka)
	
print(res)
		

Fixed code:
N, H = ( int(i) for i in input().split() )
ka = []
kb = []
for i in range(N):
	a, b = ( int(i) for i in input().split() )
	ka.append(a)
	kb.append(b)
	
kb.sort()
kb.reverse()
ma = max(ka)

hp = H
res = 0
for b in kb:
	if b < ma:
		continue
	hp = hp - b
	res += 1
	if hp <= 0:
		break
else:
	res += (hp + ma - 1)//ma
	
print(res)
Buggy code:
from operator import itemgetter
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)] 

ab.sort(key=itemgetter(0))

amax = max([i[0] for i in ab]) 
num = 0
dmg = 0

for a, b in ab:
    if b > amax:
        num += 1
        dmg += b
        if dmg >= H:
            jdg = True
            break
if not jdg:
    num += math.ceil((H - dmg) / amax)
print(num)

Fixed code:
from operator import itemgetter
import math
N, H = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(N)] 

ab.sort(key=itemgetter(1), reverse=True)

amax = max([i[0] for i in ab]) 
num = 0
dmg = 0
jdg = False

for a, b in ab:
    if b > amax:
        num += 1
        dmg += b
        if dmg >= H:
            jdg = True
            break
if not jdg:
    num += math.ceil((H - dmg) / amax)
print(num)
Buggy code:
throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)  

Fixed code:
throw = []
blow = 0
cnt = 0
n,h = map(int, input().split())
for _ in range(n):
  a,b = map(int, input().split())
  blow = max(blow,a)
  throw.append(b)
throw.sort()
while h>0 and throw and throw[-1]>blow:
  h -= throw.pop()
  cnt += 1
if h > 0:
  cnt += h//blow + (h%blow>0)
print(cnt)
Buggy code:
#input
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)
#manipulation
count = 0
a = max(A)
B.sort(reverse=True)
for b in B:
    h -= b
    count += 1
    if b < a:
        break
count += (h + a - 1) // a
#output
print(count)

Fixed code:
#input
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)
#manipulation
count = 0
a = max(A)
B.sort(reverse=True)
for b in B:
    if (b > a) & (h > 0):
        h -= b
        count += 1
if h > 0:
    count += (h + a - 1) // a
#output
print(count)
Buggy code:
import math

n, h = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(n)]

aL = []
bL = []
for a, b in abL:
    aL.append(a)
    bL.append(b)
aL = sorted(aL)
bL = sorted(bL)

aMax = max(aL)
ans = 0
while h != 0:
    if h <= 0:
        break
    if len(bL) == 0 or bL[-1] < aMax:
        ans += h // aMax
        break
    ans += 1
    h -= bL.pop()

print(ans)

Fixed code:
import math

n, h = map(int, input().split(" "))
abL = [list(map(int, input().split(" "))) for _ in range(n)]

aL = []
bL = []
for a, b in abL:
    aL.append(a)
    bL.append(b)
aL = sorted(aL)
bL = sorted(bL)

aMax = max(aL)
ans = 0
while h != 0:
    if h <= 0:
        break
    if len(bL) == 0 or bL[-1] < aMax:
        ans += math.ceil(h / aMax)
        break
    ans += 1
    h -= bL.pop()

print(ans)
Buggy code:
def main():
    n,h = list(map(int, input().split()))
    bi = []
    max_attack = [0,0]
    for i in range(n):
        a, b = list(map(int, input().split()))
        bi.append(b)
        max_attack[0] = max(a, max_attack[0])
        max_attack[1] = max(b, max_attack[1])
    bi.sort(reverse=True)
    idx = 0
    count = 0
    while h > 0:
        damage = 0
        if max_attack[0] < bi[idx]:
            damage = bi[idx]
            idx += 1
        else:
            # count += max_attack[0] // h
            count += h // max_attack[0]
            break
        h -= damage
        count += 1
    print(count)



if __name__ == '__main__':
    main()


Fixed code:
def main():
    n,h = list(map(int, input().split()))
    bi = []
    max_attack = [0,0]
    for i in range(n):
        a, b = list(map(int, input().split()))
        bi.append(b)
        max_attack[0] = max(a, max_attack[0])
        max_attack[1] = max(b, max_attack[1])
    bi.sort(reverse=True)
    idx = 0
    count = 0
    while h > 0:
        damage = 0
        if idx < len(bi) and max_attack[0] < bi[idx]:
            damage = bi[idx]
            idx += 1
        else:
            count += h // max_attack[0]
            count += 0 if h % max_attack[0] == 0 else 1
            break
        h -= damage
        count += 1
    print(count)



if __name__ == '__main__':
    main()
Buggy code:
from bisect import bisect_right,bisect_left
import sys
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()
ama=max(A)
x = bisect_right(B,ama)
ans = 0
if x ==N:
    ans = H//ama +1
    print(ans)
    sys.exit()
for i in range(x,N):
    if H<=0:
        print(ans)
        sys.exit()
    if H>0:
        H-=B[i]
        ans +=1
if H>0:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama 
print(ans)

Fixed code:
from bisect import bisect_right,bisect_left
import sys
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()
ama=max(A)
x = bisect_right(B,ama)
ans = 0
if x ==N:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
    print(ans)
    sys.exit()
for i in range(N-1,x-1,-1):
    if H<=0:
        print(ans)
        sys.exit()
    else:
        H-=B[i]
        ans +=1
if H>0:
    if H%ama ==0:
        ans += H//ama 
    else:
        ans += H//ama +1
print(ans)
Buggy code:
N, H = input().strip().split(' ')
N, H =[int(N),int(H)]
L =list()
for i in range(0,N):
    X, Y = input().strip().split(' ')
    X, Y =[int(X), int(Y)]
    L.append([X,Y])

L0 = list()
for i in range(0,N):
    L0.append(L[i][0])

L1 = list()
for i in range(0,N):
    L1.append(L[i][1])

M = max(L0)
L2 = list()

for i in range(0,N):
    if L1[i] > M:
        L2.append(L1[i])

for i in range(0,len(L2)):
    for j in range(i, len(L2)-1):
        if L2[j] < L2[j+1]:
            Y = L2[j+1]
            L2[j+1] = L2[j]
            L2[j] = Y

count = 0

for i in range(0,len(L2)):
    if H > 0:
        H -= L2[i]
        count += 1
        if H <= 0:
            print(count)

if H > 0:
    count += H//M
    print(count)

Fixed code:
N, H = input().strip().split(' ')
N, H =[int(N),int(H)]
L =list()
for i in range(0,N):
    X, Y = input().strip().split(' ')
    X, Y =[int(X), int(Y)]
    L.append([X,Y])

L0 = list()
for i in range(0,N):
    L0.append(L[i][0])

L1 = list()
for i in range(0,N):
    L1.append(L[i][1])

M = max(L0)
L2 = list()

for i in range(0,N):
    if L1[i] > M:
        L2.append(L1[i])

L2 = sorted(L2)

L2 = L2[::-1]

count = 0

for i in range(0,len(L2)):
    if H > 0:
        H -= L2[i]
        count += 1
        if H <= 0:
            print(count)

if H > 0:
    if H % M == 0:
        count += H//M
        print(count)
    else:
        count = count + H//M + 1
        print(count)
Buggy code:
import sys
import math

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

a = []
b = []
result = -1

for i in range(N):
    (ai,bi) = tuple(map(int, input().split(" ")))
    a.append(ai)
    b.append(bi)

a_max = max(a)
sorted(b).reverse()
b_length = len(b)

for i, bi in enumerate(b):
    if bi < a_max:
        b_length = i

S = 0

for l in range(b_length):
    S += b[l]
    if S >= H:
        result = l + 1
        print(result)
        sys.exit()

j = b_length

result = b_length + int(math.ceil((H - S)/a_max))

print(result)


Fixed code:
import sys
import math

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

a = []
b = []
result = 0

for i in range(N):
    (ai,bi) = tuple(map(int, input().split(" ")))
    a.append(ai)
    b.append(bi)

a_max = max(a)
b.sort()
b.reverse()
b_length = len(b)

for i, bi in enumerate(b):
    if bi < a_max:
        b_length = i
        break


S = 0

for l in range(b_length):
    S += b[l]
    if S >= H:
        result = l + 1
        print(result)
        sys.exit()


result = b_length + int(math.ceil((H - S)/a_max))

print(result)
Buggy code:
T=0

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)

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

if H>0:
    T+=int(H/A[0])

print(T)


Fixed code:
T=0

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)

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

if H>0:
    T+=int(H/A[0])
    if H%A[0]>0:
        T+=1

print(T)
Buggy code:
N, H = map(int, input().split())

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

B.sort(reverse=True)

res = 0
for b in B:
    if b > Amax:
        if H < b:
            print(res)
            exit()
        H -= b
        res += 1
    else:
        break

print(res + (H // Amax + int(H % Amax != 0)))


Fixed code:
N, H = map(int, input().split())

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

B.sort(reverse=True)

res = 0
for b in B:
    if b > Amax:
        res += 1
        if H <= b:
            print(res)
            exit()
        H -= b
    else:
        break

print(res + (H // Amax + int(H % Amax != 0)))
Buggy code:
import math
n,m=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(n):
  a0,b0=[int(i) for i in input().split()]
  a.append(a0)
  b.append(b0)
a.sort(reverse=True)
b.sort(reverse=True)
x=0
while m>0:
  if b[0]>a[0]:
    m-=b[0]
    del b[0] 
    x+=1
  else:
    x+=math.ceil(m/a[0])
    break
    
  
print(x)

Fixed code:
import math
n,m=[int(i) for i in input().split()]
a=[]
b=[]
for i in range(n):
  a0,b0=[int(i) for i in input().split()]
  a.append(a0)
  b.append(b0)
a.sort(reverse=True)
b.sort(reverse=True)
x=0
while m>0:
  if b==[]:
    x+=math.ceil(m/a[0])
    break
  else:
    if b[0]>a[0]:
      m-=b[0]
      del b[0] 
      x+=1
    else:
      x+=math.ceil(m/a[0])
      break
    
print(x)
Buggy code:
N,H = map(int,input().split())
a=[]
b=[]
for i in range(N):
	ai,bi = map(int,input().split())
	a.append(ai)
	b.append(bi)

a.sort(reverse=True)  #[4,3,2,1]
b.sort()  #[3,4,5,6]

lenb=len(b)

'''
for i in range(lenb):
	if a[0] > b[0]:
		del b[0]
	else:
		break
'''
cut = 0

for x in b:
	H -= x
	cut +=1

ans = int(H%a[0])
#print('{}%{}={}'.format(H,a[0],ans))

if ans == 0: ans = H/a[0]+cut
else: ans =(H/a[0])+1+cut

print(int(ans))

Fixed code:
N,H = map(int,input().split())
a=[]
b=[]
for i in range(N):
	ai,bi = map(int,input().split())
	a.append(ai)
	b.append(bi)

a.sort(reverse=True)  #[4,3,2,1]
b.sort(reverse=True)  #[3,4,5,6]

lenb=len(b)

for i in range(lenb):
	if a[0] > b[-1]:
		del b[-1]
	else:
		break
cut = 0

for x in b:
	H -= x
	cut +=1
	if(H<=0):
		print(cut)
		quit()

ans = int(H%a[0])
#print('{}%{}={}'.format(H,a[0],ans))

if ans == 0: ans = H/a[0]+cut
else: ans =(H/a[0])+1+cut

print(int(ans))