qyliang/CodeNanoFix huggingface dataset:
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)
ma=max(A)
BB=[]
for i in range(n):
  if B[i]>ma:
    BB.append(B[i])
BB.sort(reverse=True)
count=0
dmg=0
while dmg<h:
  if count<len(BB):
    dmg+=BB[count]
    count+=1
  else:
    dmg+=ma
    count+=1
print(count)

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)
ma=max(A)
BB=[]
for i in range(n):
  if B[i]>ma:
    BB.append(B[i])
BB.sort(reverse=True)
count=0
dmg=0
while dmg<h:
  if count<len(BB):
    dmg+=BB[count]
    count+=1
  else:
    r=(h-dmg-1)//ma+1
    dmg=h
    count+=r
print(count)
Buggy code:
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
b = [i for i in b if i>a]
b.sort().reverse()
if h <= sum(b):
	num,i = 0,0
	while h > 0:
		h -= b[i]
		num += 1
		i += 1
else:
	h -= sum(b)
	num = (h+a-1)//a + len(b)
print(num)

Fixed code:
n,h = (int(i) for i in input().split())
x = [[int(i) for i in input().split()] for i in range(n)]
a,b = 0,[]
for j in x:
	if a < j[0]: a = j[0]
	b.append(j[1])
b = [i for i in b if i>a]
b.sort()
b = b[::-1]
if h <= sum(b):
	num,i = 0,0
	while h > 0:
		h -= b[i]
		num += 1
		i += 1
else:
	h -= sum(b)
	num = (h+a-1)//a + len(b)
print(num)
Buggy code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]
    bs.sort(reverse = True)
    res = 0
    for i in bs:
        if i>=tmp:
            res+=1
            h-=i
            if(h<=0):
                break
        else:
            res += math.ceil(h/tmp)
            break

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


Fixed code:
from collections import defaultdict,deque
import math
def main():
    n,h=map(int, input().split())
    ab = [list(map(int, input().split())) for i in range(n)]
    tmp = max([int(i[0]) for i in ab])
    bs = [int(i[1]) for i in ab]+[0]
    bs.sort(reverse = True)
    i = 0
    res = 0
    for i in bs:
        if i>=tmp:
            res+=1
            h-=i
            if(h<=0):
                break
        else:
            res += math.ceil(h/tmp)
            break

    print(res)





if __name__ == '__main__':
    main()
Buggy code:
N, H = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
A, B = map(list, zip(*AB))
B.sort()
X = max(A)
S = sum(B)

cnt = (H - S + X - 1) // X
# cnt = 0
# while H > S:
#     H -= X
#     cnt += 1
for b in B[::-1]:
    H -= b
    cnt += 1
    if H <= 0: break
print(cnt)


Fixed code:
N, H = map(int, input().split())
AB = [[int(i) for i in input().split()] for _ in range(N)]
A, B = map(list, zip(*AB))
B.sort()
X = max(A)
S = sum(B)

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

Fixed code:
NH = input().split()
N = int(NH[0])
H = int(NH[1])
a = []
b = []
for v in range(N):
    L = input().split()
    a.append(L[0])
    b.append(L[1])
a = list(map(int, a))
b = list(map(int, b))
a.sort(reverse = True)
b.sort(reverse = True)
c = 0
count = 0
while c < H:
    if len(b) > 0 and a[0] < b[0]:
        c = c + b.pop(0)
        count = count + 1 
    else:
        break
if c < H:
    count = count -(-(H - c)//a[0])
print(count)
Buggy code:
import math
n, h = map(int, input().split())
a_max = 0
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    b_list.append(b)
b_list = sorted(b_list, reverse=True)
count = 0
for i in range(len(b_list)):
    if a_max < b_list[i]:
        h -= b_list[i]
        count += 1
    else:
        count += math.ceil(h/a_max)
        break
print(count)


Fixed code:
import math
n, h = map(int, input().split())
a_max = 0
b_list = []
for i in range(n):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    b_list.append(b)
b_list = sorted(b_list, reverse=True)
count = 0
flag = 0
for i in range(len(b_list)):
    if a_max < b_list[i]:
        h -= b_list[i]
        count += 1
    else:
        flag = 1
        count += math.ceil(h/a_max)
        break
    if h <= 0:
        flag = 1
        break
if flag == 0:
    count += math.ceil(h/a_max)
print(count)
Buggy code:
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(A)
B.sort(reverse=True)

ans = 0
for b in B:
    if b < a:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

import math
ans += math.floor(H / a)

print(int(ans))


Fixed code:
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(A)
B.sort(reverse=True)

ans = 0
for b in B:
    if b < a:
        break
    H -= b
    ans += 1
    if H <= 0:
        print(ans)
        exit()

import math
ans += math.ceil(H / a)

print(int(ans))
Buggy code:
#codng utf-8
import math
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]=a
    B[i]=b
A.sort(reverse=True)
B.sort(reverse=True)
flg=0
for i in range(N):
    if B[i]<A[0]:
        l=i
        flg=1
        break
ans=0
tmp=0
if flg==0:
    for i in range(N):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
else:
    for i in range(l-1):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
        
print(ans)

Fixed code:
#codng utf-8
import math
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]=a
    B[i]=b
A.sort(reverse=True)
B.sort(reverse=True)
flg=0
for i in range(N):
    if B[i]<A[0]:
        l=i
        flg=1
        break
ans=0
tmp=0
if flg==0:
    for i in range(N):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
else:
    for i in range(l):
        ans+=1
        tmp+=B[i]
        if tmp>=H:
            break
    if tmp<H:
        ans+=math.ceil((H-tmp)/A[0])
        
print(ans)
Buggy code:
n, h = list(map(int, input().split(' ')))
k = [list(map(int, input().split(' '))) for _ in range(n)]
a = []
b = []
for i in range(n):
    a.append(k[i][0])
    b.append(k[i][1])

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h > 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        h -= a[x]
        count += 1
print(count)

Fixed code:
n, h = list(map(int, input().split(' ')))
k = [list(map(int, input().split(' '))) for _ in range(n)]
a = []
b = []
for i in range(n):
    a.append(k[i][0])
    b.append(k[i][1])

a.sort(reverse = True)
b.sort(reverse = True)
a.append(0)
b.append(0)
count = 0
x = 0
y = 0

while h > 0:
    if a[x] <= b[y]:
        h -= b[y]
        y += 1
        count += 1
    elif a[x] > b[y]:
        count += h//a[x]
        if h%a[x] != 0:
            count += 1
        h = 0
print(count)
Buggy code:
import bisect

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

A_max = max(A)
B = sorted(B)

B_ind = bisect.bisect_left(B,A_max,0,N)
print(B_ind,B[B_ind:])
sumB  = sum(B[B_ind:])

if sumB >= H:
    cnt = 0
    while H > 0:
        cnt += 1
        b = B[N - cnt]
        H -= b

    ans = cnt
else:
    H -= sumB
    ans = N - B_ind

    ans += H//A_max + min(1,H%A_max)

print(ans)


Fixed code:
#import bisect

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

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

#B_ind = bisect.bisect_left(B,A_max,0,N)
#print(B_ind,B[B_ind:])

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

    H -= b

if H > 0:
    ans += H//A_max + min(1,H%A_max)

print(ans)

# if sumB >= H:
#     cnt = 0
#     while H > 0:
#         cnt += 1
#         b = B[N - cnt]
#         H -= b

#     ans = cnt
# else:
#     H -= sumB
#     ans = N - B_ind

#     ans += H//A_max + min(1,H%A_max)

# print(ans)
Buggy code:
N,H=list(map(int,input().split()))
a = 0
b = [0]
for i in range(N):
    A = list(map(int,input().split()))
    a = max(a,A[0])
    b = sorted(b+[A[1]])[::-1]
for i in range(N):
    if(H<=0):
        break
    if (b[i] > a):
        H -= b[i]
    else:
        i += int(H/a)+(0!=H%a)
        break
print(i)

Fixed code:
N, H = list(map(int,input().split()))
a = 0
b = [0]
for i in range(N):
    A = list(map(int,input().split()))
    a = max(a,A[0])
    b += [A[1]]
b = sorted(b)[::-1]
for i in range(N+1):
    if(H<=0):
        break
    if (b[i] > a):
        H -= b[i]
    else:
        i += int(H/a)+(0!=H%a)
        break
print(i)
Buggy code:
A = list(map(int,input().split()))
H = A[1]
N = A[0]

a = [0]
b = [0]

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

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

countb = 0

while(H > 0):
    if (b[countb] > a[0]):
        H -= b[countb]
        countb += 1
        continue
    else:
        break
print(countb + int(H/a[0]) + (0!=(H%a[0])))

    


Fixed code:
A = list(map(int,input().split()))
H = A[1]
N = A[0]

a = [0]
b = [0]

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

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

countb = 0

while(H > 0):
    if (b[countb] > a[0]):
        H -= b[countb]
        countb += 1
        continue
    else:
        break

if(H<0):
    print(countb)
    exit()
print(countb + int(H/a[0]) + (0!=(H%a[0])))
Buggy code:
from math import ceil
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())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] => ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)


Fixed code:
from math import ceil
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())
bs = list(sorted(b,reverse=True))
ma = max(a)
ret = 0
while ret < n:
    if bs[0] > ma:
        h -= bs[0]
        bs.pop(0)
        ret += 1
        if h <= 0 : break
    else:
        break

if h > 0: ret += ceil(h/ma)
print(ret)
Buggy code:
R = lambda type_ = "int": list(map(eval(type_), input().split(' ')))

N, H = R()
a, b = 0, []
while N:
    a_, b_ = R()
    b.append(b_)
    a = max(a, a_)
    N -= 1

b.sort()
i = len(b) - 1
while i >= 0 and H > 0 and b[i] >= a:
    H -= b[i]
    i -= 1
    
if i < 0 and H > 0:
    print(len(b) + (H - 1) // a + 1)
elif H <= 0:
    print(len(b) - i)
elif a > b[i]:
    print(len(b) - i - 1 + (H- 1) // a + 1)


Fixed code:
R = lambda type_ = "int": list(map(eval(type_), input().split(' ')))

N, H = R()
a, b = 0, []
while N:
    a_, b_ = R()
    b.append(b_)
    a = max(a, a_)
    N -= 1

b.sort()
i = len(b) - 1
while i >= 0 and H > 0 and b[i] >= a:
    H -= b[i]
    i -= 1
    
if i < 0 and H > 0:
    print(len(b) + (H - 1) // a + 1)
elif H <= 0:
    print(len(b) - i - 1)
elif a > b[i]:
    print(len(b) - i - 1 + (H - 1) // a + 1)
Buggy code:
N,H = map(int,input().split())
katana = []
damage = 0
for n in range(N):
    katana.append(list(map(int,input().split())))

katanaA = sorted(katana,reverse = True)
katanaB = sorted(katana, key = lambda x:x[1],reverse = True)
numb = 0
num = 0
check = True
while damage < H:
    if katanaA[0][0] <= katanaB[numb][1] and check:
        damage += katanaB[numb][1]
        numb += 1
        if numb == N:
            numb = N-1
            check = False
    else:
        num += (H-damage)//katanaA[0][0] - 1
        damage = H
    num += 1 
print(num)


Fixed code:
N,H = map(int,input().split())
katana = []
damage = 0
for n in range(N):
    katana.append(list(map(int,input().split())))

katanaA = sorted(katana,reverse = True)
katanaB = sorted(katana, key = lambda x:x[1],reverse = True)
numb = 0
num = 0
check = True
while damage < H:
    if katanaA[0][0] <= katanaB[numb][1] and check:
        damage += katanaB[numb][1]
        numb += 1
        if numb == N:
            numb = N-1
            check = False
    else:
        num += (H-damage)//katanaA[0][0]
        if  (H-damage)%katanaA[0][0] == 0:
            num -= 1
        damage = H
    num += 1 
print(num)
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)

ans = 0
amax = max(a)
b.sort(reverse=True)
# print(amax, b)
i = 0
while H > 0:
    if amax < b[i]:
        H -= b[i]
        ans += 1
        i += 1
    else:
        ans += H//amax
        if H%amax != 0:
            ans += 1
        break

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

ans = 0
amax = max(a)
b.sort(reverse=True)
# print(amax, b)
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)
Buggy code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    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.sort(reverse = True)
    ans = 0
    m = max(a)
    bit = 0
    for i in range(n):
        if b[i] > m:
            h -= b[i]
            ans += 1
        else:
            break
        if h <= 0:
            print(ans)
            bit = 1
            break
    if bit == 0:
        ans += math.ceil(h/m)
        print(ans)
    return 0
 
if __name__ == "__main__":
    solve()


Fixed code:
import numpy as np
import functools
import math
import scipy
import fractions
import itertools

def solve():
    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.sort(reverse = True)
    b.sort(reverse = True)
    ans = 0
    m = max(a)
    bit = 0
    for i in range(n):
        if b[i] > m:
            h -= b[i]
            ans += 1
        if h <= 0:
            print(ans)
            bit = 1
            break
    if bit == 0:
        ans += math.ceil(h/m)
        print(ans)
    return 0
 
if __name__ == "__main__":
    solve()
Buggy code:
from math import ceil
n,h=map(int,input().split())
g=[list(map(int,input().split())) for i in range(n)]
l=[]
ans=0
dm=0
for i in range(n):
  l.append([g[i][0],2])
  l.append([g[i][1],1])
l.sort(reverse=True)
for i in range(2*n):
  if l[i][1]==1:
    dm+=l[i][0]
    ans+=1
    if dm>=h:
      print(ans)
      exit()
  else:
    h-=dm
    ans+=ceil(h//l[i][0])
    print(ans)
    exit()
    

Fixed code:
from math import ceil
n,h=map(int,input().split())
g=[list(map(int,input().split())) for i in range(n)]
l=[]
ans=0
dm=0
for i in range(n):
  l.append([g[i][0],2])
  l.append([g[i][1],1])
l.sort(reverse=True)
for i in range(2*n):
  if l[i][1]==1:
    dm+=l[i][0]
    ans+=1
    if dm>=h:
      print(ans)
      exit()
  else:
    h-=dm
    ans+=ceil(h/l[i][0])
    print(ans)
    exit()
Buggy code:
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b = map(int,input().split())
    A = max(A,a)
    B.append(b)
B = sorted(reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

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


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

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

ans = 0
for i in range(len(B)):
    H -= B[i]
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H -1)//A + 1)
Buggy code:
from collections import deque
N,H = map(int,input().split())
A=[]
B=[]
d=deque()
max_axe = 0
max_throw = 0
ans=0
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 B:
    if i>=A[0]:
        H-=i
        ans+=1
    else:
         break

ans+=int(-(-H/A[0]))

print(ans)

Fixed code:
from collections import deque
N,H = map(int,input().split())
A=[]
B=[]
d=deque()
max_axe = 0
max_throw = 0
ans=0
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 B:
    if i>=A[0]:
        H-=i
        ans+=1
        if H<=0:break
    else:
        break

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

print(ans)
Buggy code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    i = 0

    while i < N and H > 0:
        a, b, ken_i = ab[i]
        if b < a_max:
            break
        H -= b
        cnt += 1
        i += 1

    if H > 0:
        H -= b_max
        cnt += 1

    if H > 0:
        cnt += (math.ceil(H / a_max))

    print(cnt)
    
main()



Fixed code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N, H = LI()
    ab = []
    for i, _ in enumerate(range(N)):
        _ab = LI()
        ab.append((_ab[0], _ab[1], i))
    a_max, b_max, a_max_i = sorted(ab, key=lambda x:x[0])[-1]
    ab = sorted(ab, key=lambda x:x[1])[::-1]
    cnt = 0
    i = 0

    while i < N and H > 0:
        a, b, ken_i = ab[i]
        if b < a_max:
            break
        H -= b
        cnt += 1
        i += 1

    if H > 0:
        cnt += (math.ceil(H / a_max))

    print(cnt)
    
main()
Buggy code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
B.sort()
C = iter(B[B > m][::-1])

count = 0

while H > 0:
    try:
        d = next(C)
    except StopIteration:
        Q, R = 0, 0
        break
    else:
        H -= d
        count += 1
else:
    Q, R = divmod(H, m)

print(count + Q + bool(R))


Fixed code:
import numpy as np
N, H = map(int, input().split())
A, B = np.array(tuple(tuple(map(int, input().split())) for _ in range(N))).T

m = A.max()
B.sort()
C = iter(B[B > m][::-1])

count = 0

try:
    while H > 0:
        H -= next(C)
        count += 1
except StopIteration:
    Q, R = divmod(H, m)
    print(count + Q + bool(R))
else:
    print(count)
Buggy code:
n,h=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append([b,0]);a.append([c,1])
a.sort(reverse=1)
i=0
ans=0
while h>0:
  if a[i][1]==1:h-=a[i][0];ans+=1
  else:h=0:ans+=(h-1)//a[i][0]+1
print(ans)

Fixed code:
n,h=map(int,input().split())
a=[]
for i in range(n):
  b,c=map(int,input().split())
  a.append([b,0]);a.append([c,1])
a.sort(reverse=1)
i=b=0
while h>0:
  if a[i][1]==1:h-=a[i][0];b+=1
  else:b+=(h-1)//a[i][0]+1;h=0
  i+=1
print(b)
Buggy code:
from bisect import bisect

n,h=map(int,input().split())
a=[]
b=[]
a_max=0
b_max=0
for i in range(n):
  x,y=map(int,input().split())
  a.append(x)
  b.append(y)
  a_max=max(a_max,x)
  b_max=max(b_max,y)

if a.index(a_max)==b.index(b_max):
  a=sorted(a)
  a_max=a[-2]

b=sorted(b)
lim_inx=bisect(b,a_max)

cnt=0
total=0
inx=n-1
while total<=h:
  if inx>=lim_inx:
    total+=b[inx]
    cnt+=1
    inx-=1
  else:
    if (h-total)%a_max==0:
      cnt+=(h-total)//a_max
    else:
      cnt+=(h-total)//a_max+1
    print(cnt)
    exit()
print(cnt)

Fixed code:
from bisect import bisect

n,h=map(int,input().split())
b=[]
a_max=0
for i in range(n):
  x,y=map(int,input().split())
  b.append(y)
  a_max=max(a_max,x)

b=sorted(b)
lim_inx=bisect(b,a_max)

cnt=0
total=0
inx=n-1
while total<h:
  if inx>=lim_inx:
    total+=b[inx]
    cnt+=1
    inx-=1
  else:
    if (h-total)%a_max==0:
      cnt+=(h-total)//a_max
    else:
      cnt+=(h-total)//a_max+1
    print(cnt)
    exit()
print(cnt)
Buggy code:
N,H=map(int,input().split())
L=[[0,0]for i in range(N)]

for i in range(N):
    L[i][0],L[i][1]=map(int,input().split())
L=sorted(L,key=lambda x: (x[0]))

d=L[N-1][0]
L2=sorted(L,key=lambda x: (x[1]))

c=0
for i in range(N-1,-1,-1):
    if(d<=L2[i][1]):
        break
    c+=1
    H-=L2[i][1]
    if(H<0):
        break
    
if(H>0):
    if(H%d!=0):
        c+=1
    c+=(H//d)


print(c)


Fixed code:
N,H=map(int,input().split())
L=[[0,0]for i in range(N)]

for i in range(N):
    L[i][0],L[i][1]=map(int,input().split())
L=sorted(L,key=lambda x: (x[0]))

d=L[N-1][0]
L2=sorted(L,key=lambda x: (x[1]))

c=0
for i in range(N-1,-1,-1):
    if(d>=L2[i][1]):
        break
    c+=1
    H-=L2[i][1]
    if(H<=0):
        break

if(H>0):
    if(H%d!=0):
        c+=1
    c+=(H//d)


print(c)
Buggy code:
import math
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // a + 1 )

Fixed code:
N, H = list(map(int, input().split()))
maxA = 0
n = 0
b = []
for _ in range(N):
    ta, tb = list(map(int, input().split()))
    maxA = max(maxA, ta)
    b.append(tb)

b = list(filter(lambda x: x > maxA, b))
b.sort()

while H > 0 and b:
    H -= b.pop()
    n += 1

print(n + max(H-1, -1) // maxA + 1 )