qyliang/CodeNanoFix huggingface dataset:
Buggy code:
def main():
    from sys import stdin
    input = lambda :stdin.readline().rstrip()
    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() #
    a = A.pop()
    b = B.pop()
    ans = 0
    from math import ceil
    while H > 0:
        if b > a:
            ans += 1
            H -= b
            if B:
                b = B.pop()
            continue
            
        
        ans += ceil(H/a)
        print(ans)
        return



main()
        

        

Fixed code:
def main():
    from sys import stdin
    input = lambda :stdin.readline().rstrip()
    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() #
    a = A.pop()
    b = B.pop()
    ans = 0
    from math import ceil
    while H > 0:
        if b > a:
            ans += 1
            H -= b
            if B:
                b = B.pop()
            else:
                b = 0
                
            
        else:
            ans += ceil(H/a)
            break
    print(ans)
    return

main()
Buggy code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)

N,H = I()
A = []
B = []
for i in range(N):
    a,b = I()
    A.append(a)
    B.append(b)
B.sort(reverse=True)
huru = max(A)
cnt = 0
for i in range(N):
    if B[i] < huru:
        break
    H -= B[i]
    cnt += 1
    if H <= 0:
        print(cnt)
print(cnt+math.ceil(H/huru))

Fixed code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10**9)

N,H = I()
A = []
B = []
for i in range(N):
    a,b = I()
    A.append(a)
    B.append(b)
B.sort(reverse=True)
huru = max(A)
cnt = 0
for i in range(N):
    if B[i] < huru:
        break
    H -= B[i]
    cnt += 1
    if H <= 0:
        print(cnt)
        exit()
print(cnt+math.ceil(H/huru))
Buggy code:
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())

amax=max(a)
n=0
total=0
b.sort(reverse=True)
for i in range(N):
  if b[i] > amax:
    n+=1
    total+=b[i]
  else:
    break

if H <= total:
  for i in range(n):
    H-=b[i]
    if H <＝0:
      print(i+1)
      break
else:
  print(n+int((H-total-1)/amax)+1)

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

amax=max(a)
n=0
total=0
b.sort(reverse=True)
for i in range(N):
  if b[i] > amax:
    n+=1
    total+=b[i]
  else:
    break

if H <= total:
  for i in range(n):
    H-=b[i]
    if H <= 0:
      print(i+1)
      break
else:
  print(n+int((H-total-1)/amax)+1)
Buggy code:
import sys
sys.setrecursionlimit(10 ** 7)
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())

amax = max(a)
ans = 0

b.sort(reverse=True)

for attack in b:

    if attack < amax: break
    h -= attack
    ans += 1
    if h <= 0:
        exit()

ans += -(-h//amax)

print(ans)


Fixed code:
import sys
sys.setrecursionlimit(10 ** 7)
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())

amax = max(a)
ans = 0

b.sort(reverse=True)

for attack in b:

    if attack < amax: break
    h -= attack
    ans += 1
    if h <= 0:
        print(ans)
        exit()

ans += -(-h//amax)

print(ans)
Buggy code:
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
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+1
    else:
        cnt+=(h-ans)//amax
        
print(cnt)


Fixed code:
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
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)
Buggy code:
#085-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import math
n,h=IL()
a=0
B=[0]*n
for i in range(n):
    ta,tb=IL()
    a=max(a,ta)
    B[i]=tb
ans=0
for i in range(n):
    if B[-1-i]>=a and h>0:
        h-=B[-1-i]
        ans+=1
    else:
        break
if h>0:
    ans+=math.ceil(h/a)
print(ans)

Fixed code:
#085-D
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(input())
def S(): return list(input())
import math
n,h=IL()
a=0
B=[0]*n
for i in range(n):
    ta,tb=IL()
    a=max(a,ta)
    B[i]=tb
B.sort()
ans=0
for i in range(n):
    if B[-1-i]>=a and h>0:
        h-=B[-1-i]
        ans+=1
    else:
        break
if h>0:
    ans+=math.ceil(h/a)
print(ans)
Buggy code:
import math
N, H = map(int, input().split())
cut_max = 0
throw = [0 for _ in range(N)]
throw_sum = 0
for i in range(N):
    cut, throw[i] = map(int, input().split())
    if cut > cut_max:
        cut_max = cut
throw.sort(reverse=True)
for i in range(N):
    if cut_max <= throw[i]:
        throw_sum += throw[i]
        if throw_sum >= H:
            print(i+2)
            exit()
    else:
        break
print(i + 1 + math.ceil((H-throw_sum)/cut_max))






Fixed code:
import math
N, H = map(int, input().split())
cut_max = 0
throw = [0 for _ in range(N)]
throw_max = []
throw_sum = 0
for i in range(N):
    cut, throw[i] = map(int, input().split())
    if cut > cut_max:
        cut_max = cut
throw.sort(reverse=True)
for i in range(N):
    if cut_max < throw[i]:
        throw_max.append(throw[i])
        throw_sum += throw[i]
        if throw_sum >= H:
            print(i+1)
            exit()
    else:
        break
print(len(throw_max) + math.ceil((H-throw_sum)/cut_max))
Buggy code:
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + int(hp / max_slash + 0.9999999))

n, hp = map(int, input().split())
takanas = [map(int, input().split()) for _ in range(n)]
katana(hp, takanas)

Fixed code:
import math
import numpy as np

def katana(hp, katanas):
    katanas = np.array(katanas, 'i')
    max_slash = np.max(katanas[:, 0])
    throws = -np.sort(-katanas[:, 1])
    throws_index = np.where(throws > max_slash)[0]
    eff_throws = throws[throws_index]

    for i, v in enumerate(eff_throws):
        hp -= v
        if hp <= 0:
            print(i + 1)
            return

    print(len(eff_throws) + math.ceil(hp / max_slash))

n, hp = map(int, input().split())
takanas = [list(map(int, input().split())) for _ in range(n)]
katana(hp, takanas)
Buggy code:
N, H = map(int, input().split())
alist = []
blist = []
for i in range(N):
    A, B = map(int, input().split())
    alist.append(A)
    blist.append(B)

maxa = max(alist)
blist = list(filter(lambda el: el > maxa, blist))

def mergesort(l):
    def merge(left, right):
        result = []
        while left and right:
            if left[0] <= right[0]:
                result.append(left.pop(0))
            else:
                result.append(right.pop(0))
        return result + left + right

    length = len(l)
    if length <= 1:
        return l
    middle = length // 2
    return merge(mergesort(l[:middle]), mergesort(l[middle:]))

blist = mergesort(blist)
blist.reverse()

sum_for_h = 0
ans = 0
for i in blist:
    sum_for_h += i
    ans += 1
    if sum_for_h >= H:
        print(ans , flush=True)
        exit()

anum = (H-sum_for_h) // maxa
print(ans + anum, flush=True)


Fixed code:
N, H = map(int, input().split())
alist = []
blist = []
for i in range(N):
    A, B = map(int, input().split())
    alist.append(A)
    blist.append(B)

maxa = max(alist)
blist = list(filter(lambda el: el > maxa, blist))

def mergesort(l):
    def merge(left, right):
        result = []
        while left and right:
            if left[0] <= right[0]:
                result.append(left.pop(0))
            else:
                result.append(right.pop(0))
        return result + left + right

    length = len(l)
    if length <= 1:
        return l
    middle = length // 2
    return merge(mergesort(l[:middle]), mergesort(l[middle:]))

blist = mergesort(blist)
blist.reverse()

sum_for_h = 0
ans = 0
for i in blist:
    sum_for_h += i
    ans += 1
    if sum_for_h >= H:
        print(ans , flush=True)
        exit()

anum = (H-sum_for_h) / maxa
import math
anum = math.ceil(anum)
print(ans + anum, flush=True)
Buggy code:
import math
N,H = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
maxa = max(A)
B.sort(reverse=True)
c = 0
for c in range(N):
    if B[c] >= maxa:
        H-=B[c]
        if H <= 0:
            break
    else:
        break
if H <= 0:
    print(c+1)
else:
    c+=1
    c+=math.ceil(H/maxa)
    print(c)

Fixed code:
import math
N,H = map(int,input().split())
A = []
B = []
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
maxa = max(A)
B.sort(reverse=True)
c = 0
for c in range(N):
    if B[c] >= maxa:
        H-=B[c]
        if H <= 0:
            c+=1
            break
        elif c == N-1:
            c+=1
    else:
        break
if H <= 0:
    print(c)
else:
    c+=math.ceil(H/maxa)
    print(c)
Buggy code:
import numpy as np
n, h =[int(i) for i in input().split()]
a = np.empty(n,dtype=int)
b = np.empty(n,dtype=int)
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
sort_b = np.sort(b)
max_a = np.max(a)
b_big = b[b>=max_a]
b_sum = np.sum(b_big)
b_biglen= b_big.shape[0]
if b_sum >= h:
    ret = np.sum(b_big[::-1].cumsum() <h)
else:
    ret = b_big.shape[0]
    ret += np.ceil((h -b_sum)/max_a)
print(str(int(ret)))

Fixed code:
import numpy as np
n, h =[int(i) for i in input().split()]
a = np.empty(n)
b = np.empty(n)
for i in range(n):
    a[i], b[i] = [int(i) for i in input().split()]
sort_b = np.sort(b)
max_a = np.max(a)
b_big = sort_b[sort_b>max_a]
b_sum = np.sum(b_big)
if b_sum >= h:
    ret = np.sum(b_big[::-1].cumsum() <h) + 1 
else:
    ret = b_big.shape[0]
    ret += np.ceil((h -b_sum)/max_a)
print(int(ret))
Buggy code:
N, H = map(int, input().split())
B = []
a_max = 0
for i in range(N):
    a, b = map(int, input().split())
    a_max = max(a_max, a)
    B.append(b)

B = sorted([b for b in B if b > a_max], reverse = True)

cnt = 0
for b in B:
    H -= b
    cnt += 1
    if H <= 0:
	break
if H > 0:
    cnt += ((H-1) // a_max) + 1


print(cnt)


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

B = sorted([b for b in B if b > a_max], reverse = True)

cnt = 0
for b in B:
    H -= b
    cnt += 1
    if H <= 0:
        break
if H > 0:
    cnt += ((H-1) // a_max) + 1


print(cnt)
Buggy code:
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)
else:
    a = max(A)
    B.sort()
    B.reverse()

ans = 0
for b in B:
    if H <= 0:
        print(ans)
        break

    if a < b:
        H -= b
        ans += 1
    else:
        print(ans + ceil(H / a))
        break

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

ans = 0
for b in B:
    if H <= 0:
        print(ans)
        break

    if a < b:
        H -= b
        ans += 1
else:
    print(ans + ceil(H / a))
Buggy code:
import sys
import os
import math

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)


Fixed code:
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)
Buggy code:
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

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

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B)).sort(reverse=True)

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            break

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)

Fixed code:
N, H = map(int, input().split())
# B = []
A = []
B = []
amax = -1
bmax = -1

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

    if amax < a:
        amax = a
    
    if bmax < b:
        bmax = b

if amax >= bmax:
    m = H % amax
    if m != 0:
        ans = H // amax + 1
    else:
        ans = H // amax

else:
    ans = 0
    throw_lst = list(filter(lambda x: x > amax, B))
    throw_lst.sort(reverse=True)

    for tb in throw_lst:
        H -= tb
        ans += 1
        if H <= 0:
            print(ans)
            exit(0)

    m = H % amax
    if m != 0:
        ans += H // amax + 1
    else:
        ans += H // amax

print(ans)
Buggy code:
n,h = (int(i) for i in input().split())
a = []
b = []
cnt = 0
for i in range(n):
  x,y = (int(i) for i in input().split())
  a.append(x)
  b.append(y)
max = max(a)
b.sort()
for i in b[::-1]:
  if i > max:
    h -= i
    cnt += 1

  if h <= 0:

    exit()
import math
cnt += int(math.ceil(h / max))
print(cnt)

Fixed code:
n,h = (int(i) for i in input().split())
a = []
b = []
cnt = 0
for i in range(n):
  x,y = (int(i) for i in input().split())
  a.append(x)
  b.append(y)
max = max(a)
b.sort()
for i in b[::-1]:
  if i >= max:
    h -= i
    cnt += 1
 #   print(i,h,cnt)
  if h <= 0:
    print(cnt)
    exit()
import math
cnt += int(math.ceil(h / max))
print(cnt)
Buggy code:
import math
N, H = (int(x) for x in input().split())
list = []
for i in range(N):
    list.append([int(x) for x in input().split()])

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

joint_list.sort(key = lambda x: x[0])
total_damage, ans, index = 0, 0, 2*N-1
while total_damage < H:
    if joint_list[index][1] == 1:
        total_damage += joint_list[index][0]
        index -= 1
        ans += 1
    else:
        ans += math.ceil((H - total_damage) // joint_list[index][0])
        break

print(ans)


Fixed code:
import math
N, H = (int(x) for x in input().split())
list = []
for i in range(N):
    list.append([int(x) for x in input().split()])

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

joint_list.sort(key = lambda x: x[0])
total_damage, ans, index = 0, 0, 2*N-1
while total_damage < H:
    if joint_list[index][1] == 1:
        total_damage += joint_list[index][0]
        index -= 1
        ans += 1
    else:
        ans += math.ceil((H - total_damage) / joint_list[index][0])
        break

print(ans)
Buggy code:
import math
n, h = map(int,input().split())
a=[]
b=[]

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

maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()

damage=0
cnt=0
while(h>damage):
    
    if b[0]>maxa:
        damage+=b[0]
        del b[0]
        cnt+=1
    else:
        cnt=cnt+int((h-damage)/b[0])
        #print(cnt,damage)
        damage+=b[0]*((h-damage)/b[0])
        if h>damage:
            cnt+=1
            damage+=b[0]

print(cnt)


Fixed code:
import math
n, h = map(int,input().split())
a=[]
b=[]

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

maxa=max(a)
b.append(maxa)
b.sort()
b.reverse()

damage=0
cnt=0
while(h>damage):
    
    if b[0]>maxa:
        damage+=b[0]
        del b[0]
        cnt+=1
    else:
        cnt=cnt+int((h-damage)/b[0])
        #print(cnt,damage)
        damage+=b[0]*int((h-damage)/b[0])
        if h>damage:
            cnt+=1
            damage+=b[0]

print(cnt)
Buggy code:
import math

N,H = map(int,input().split())
alis=[];blis=[]
for c in range(N):
    a,b = map(int,input().split())
    alis.append(a);blis.append(b)
a = max(alis)
blis.sort();blis.reverse()
count = 0
num = 0
for i in blis:
    if num >= H:
        print(count)
        exit()
    if i < a:
        break
    num += i
    count += 1
count += math.floor((H-num)/a)
print(count)


Fixed code:
import math

N,H = map(int,input().split())
alis=[];blis=[]
for c in range(N):
    a,b = map(int,input().split())
    alis.append(a);blis.append(b)
a = max(alis)
blis.sort();blis.reverse()
count = 0
num = 0
for i in blis:
    if num >= H:
        print(count)
        exit()
    if i < a:
        break
    num += i
    count += 1
count += math.ceil((H-num)/a)
print(count)
Buggy code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax or h <= 0:
        print(ans + h // amax + (h % amax > 0))
        break
    if h <= 0:
        print(ans)
        break
    h -= bi
    ans += 1


Fixed code:
n, h = map(int, input().split())
a, b = [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai), b.append(bi)
a.sort(), b.sort()

ans, amax = 0, a[-1]
for bi in b[::-1]:
    if bi <= amax:
        print(ans + h // amax + (h % amax > 0))
        break
    if h <= 0:
        print(ans)
        break
    h -= bi
    ans += 1
else:
    print(ans + h // amax + (h % amax > 0))
Buggy code:
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())
m = max(a)
b.sort()

ans = 0
for i in range(n):
    if m < b[i]:
        h -= b[i]
        ans += 1
        if h <= 0 :
            print(ans)
            exit()
print(h)
ans += math.ceil(h / m)
print(ans)


Fixed code:
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())
m = max(a)
b.sort(reverse=True)

ans = 0
for i in range(n):
    if m <= b[i]:
        h -= b[i]
        ans += 1
        if h <= 0:
            print(ans)
            exit()

ans += math.ceil(h / m)
print(ans)
Buggy code:
#085_D
n, h = map(int, input().split())
attacks = []
for _ in range(n):
    a, b = map(int, input().split())
    attacks.append((a, 'a'))
    attacks.append((b, 'b'))
attacks.sort(reverse= True)

cnt = 0
for damage, kind in attacks:
    if kind == 'b':
        h -= damage
        cnt += 1
        if h <= 0:
            break
            
    else:
        cnt += -(-h // a)
        break
        
print(cnt)

Fixed code:
#085_D
n, h = map(int, input().split())
attacks = []
for _ in range(n):
    a, b = map(int, input().split())
    attacks.append((a, 'a'))
    attacks.append((b, 'b'))
attacks.sort(reverse= True)

cnt = 0
for damage, kind in attacks:
    if kind == 'b':
        h -= damage
        cnt += 1
        if h <= 0:
            break
            
    else:
        cnt += -(-h // damage)
        break

print(cnt)
Buggy code:
import math
N, H = map(int, input().split())
sword =[list(map(int, input().split())) for _ in range(N)]
def f1(l):
    a, b = l
    return a
def f2(l):
    a, b = l
    return b
sword.sort(key = f1)
amax, b1 = sword[-1]
sword.sort(key = f2)
dam = 0
ans = 0
while True:
    a, b = sword.pop()
    if a == amax:
        break
    else:
        dam += b
        ans += 1 
        if dam >= H:
            break
if dam < H:
    ans += max(math.ceil((H-dam-b1)/amax), 0) + 1
print(ans)

Fixed code:
import math
N, H = map(int, input().split())
sword =[list(map(int, input().split())) for _ in range(N)]
def f1(l):
    a, b = l
    return a
def f2(l):
    a, b = l
    return b
sword.sort(key = f2)
sword.sort(key = f1)
amax, b1 = sword[-1]
sword.sort(key = f2)
dam = 0
ans = 0
while sword:
    a, b = sword.pop()
    if b < amax:
        break
    else:
        dam += b
        ans += 1 
        if dam >= H:
            break
if dam < H:
    dam -= b1
    ans -= 1
    ans += max(math.ceil((H-dam-b1)/amax), 0) + 1
print(ans)
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)
  

def solve():
  count = 0
  remain = H
  
  B.sort()
  
  max_a = max(A)
  
  while B:
    if remain <= 0:
      return count
    
    b = B.pop()
    
    if b < max_a:
      break
      
    remain -= b
    count += 1
      
  while remain > 0:
    remain -= max_a
    count += 1
    
  return count

print(solve())

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)
  

def solve():
  count = 0
  remain = H
  
  B.sort()
  
  max_a = max(A)
  
  while B:
    if remain <= 0:
      return count
    
    b = B.pop()
    
    if b < max_a:
      break
      
    remain -= b
    count += 1
  
  count += (remain + max_a - 1) // max_a
    
  return count

print(solve())
Buggy code:
from operator import itemgetter
import math
N,H = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()]for _ in range(N)]
ab.sort(key = itemgetter(1),reverse = True)
left = H
cnt = 0
max_a = max(ab,key=itemgetter(0))[0]

for i in ab:
    if(i[1]>max_a):
        left -= i[1]
        cnt += 1
    else:
        cnt += math.ceil(left/max_a)
        break
if(left>0):
    cnt += math.ceil(left/max_a)
print(cnt)


Fixed code:
from operator import itemgetter
import math
N,H = [int(x) for x in input().split()]
ab = [[int(x) for x in input().split()]for _ in range(N)]
ab.sort(key = itemgetter(1),reverse = True)
left = H
cnt = 0
max_a = max(ab,key=itemgetter(0))[0]

for i in ab:
    if(i[1]>max_a):
        left -= i[1]
        cnt += 1
    else:
        cnt += math.ceil(left/max_a)
        left = 0
        break
    
    if(left<=0):
        break
        
if(left>0):
    cnt += math.ceil(left/max_a)
print(cnt)