qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]

N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()

B = sorted(B)
a = max(A)

s = 0
e = N-1

while True:
    m = (s+e)//2
    if B[m] > a:
        e = m
    elif B[m] <= a:
        s = m
    #if s==e:
        #break
    else:
        break
    if e-s==1 and m==s:
        m += 1
        break

print(m)
rem = H - sum(B[m:])
if rem >= 0:
    if rem%a!=0:
        print((N-m)+rem//a+1)
    else:
        print((N-m)+rem//a)
else:
    for i in range(m, N):
        rem += B[i]
        if rem>=0:
            print(N-i)
            exit()
        

Fixed code:
import sys
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for i in range(N)]
def dp2(ini, i, j): return [[ini]*i for i2 in range(j)]
def dp3(ini, i, j, k): return [[[ini]*i for i2 in range(j)] for i3 in range(k)]
 
import bisect
 
 
N, H = mi()
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = mi()
 
B = sorted(B)
a = max(A)
m = bisect.bisect_right(B, a)
'''
s = 1
e = N
m = (s+e)//2
pre_m = 0
while True:
    m = (s+e)//2
    if B[m-1] > a:
        e = m
    elif B[m-1] <= a:
        s = m
    if s==e:
        m -= 1
        break
    #else:
        #break
    if e-s==1 and pre_m==m:
        break
    pre_m = m
'''
rem = H - sum(B[m:])
if rem > 0:
    print((N-m)+rem//a+(rem%a!=0))
else:
    for i in range(m, N):
        rem += B[i]
        if rem>0:
            print(N-i)
            exit()
Buggy code:
#!/usr/bin/env python3
import sys
from operator import itemgetter


def solve(N: int, H: int, A: "List[int]", B: "List[int]"):
    B.sort(reverse=True)
    maxA = max(A)

    D = 0
    res = 0

    for b in B:
        D += b
        res += 1
        if D >= H:
            print(res)
            return

    res += (H-D)//maxA + (1 if (H-D)%maxA > 0 else 0)
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)

if __name__ == '__main__':
    main()


Fixed code:
#!/usr/bin/env python3
import sys
from operator import itemgetter


def solve(N: int, H: int, A: "List[int]", B: "List[int]"):
    B.sort(reverse=True)
    maxA = max(A)

    D = 0
    res = 0

    for b in B:
        if b <= maxA:
            break

        D += b
        res += 1
        if D >= H:
            print(res)
            return

    res += (H-D)//maxA + (1 if (H-D)%maxA > 0 else 0)
    print(res)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    H = int(next(tokens))  # type: int
    a = [int()] * (N)  # type: "List[int]" 
    b = [int()] * (N)  # type: "List[int]" 
    for i in range(N):
        a[i] = int(next(tokens))
        b[i] = int(next(tokens))
    solve(N, H, a, b)

if __name__ == '__main__':
    main()
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.sort(reverse=True)
B.sort(reverse=True)
ans = 0

for b in B:
    if b>A[0] and H>0:
        H -= b
        ans += 1

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

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)
A.sort(reverse=True)
B.sort(reverse=True)
ans = 0

for b in B:
    if b>A[0] and H>0:
        H -= b
        ans += 1

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

print(ans)
Buggy code:
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 += math.ceil(HP // hit)
 
print(ans)

Fixed code:
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)
Buggy code:
n, h = input().split()
n = int(n)
h = int(h)

a = []
b = []
for i in range(n):
    a_, b_ = input().split()
    a.append(int(a_))
    b.append(int(b_))

import numpy as np
a = np.array(a)
b = np.array(b)

to_throw = b[b>max(a)]
sum_throw = sum(to_throw)

d = h - sum_throw

if d <= 0:
    cum = np.cumsum(np.sort(b)[::-1])
    print(len(to_throw) - len(cum[cum>=h])) + 1
else:
    import math
    print(len(to_throw) + math.ceil(d/max(a)))


Fixed code:
n, h = input().split()
n = int(n)
h = int(h)

a = []
b = []
for i in range(n):
    a_, b_ = input().split()
    a.append(int(a_))
    b.append(int(b_))

import numpy as np
a = np.array(a)
b = np.array(b)

to_throw = b[b>max(a)]
sum_throw = sum(to_throw)

d = h - sum_throw

if d <= 0:
    cum = np.cumsum(np.sort(to_throw)[::-1])
    print(len(to_throw) - len(cum[cum>=h]) + 1)
else:
    import math
    print(len(to_throw) + math.ceil(d/max(a)))
Buggy code:
import math

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

A=[]
B=[]
for n in range(N):
    a,b = list(map(int,input_[1+n].split()))
    A.append(a)
    B.append(b)
    
A.sort(reverse=True)
B.sort(reverse=True)
A,B

a_max=A[0]

B_=[]
for b in B:
    if b < a_max:
        break
    B_.append(b)
B=B_

B_sum = [0]
for b in B:
    B_sum.append(B_sum[-1]+b)

ans = 0
for b_sum_idx,b_sum in enumerate(B_sum):
    if b_sum >= H:
        ans = b_sum_idx
        break
        
    ans = b_sum_idx
H = max(0,H - b_sum)

ans += math.ceil(H/a_max)

print(ans)

Fixed code:
import math

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

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

a_max=A[0]

B_=[]
for b in B:
    if b < a_max:
        break
    B_.append(b)
B=B_

B_sum = [0]
for b in B:
    B_sum.append(B_sum[-1]+b)

ans = 0
for b_sum_idx,b_sum in enumerate(B_sum):
    if b_sum >= H:
        ans = b_sum_idx
        break
        
    ans = b_sum_idx
H = max(0,H - b_sum)

ans += math.ceil(H/a_max)

print(ans)
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())
aa = sorted(A,key=lambda x: -x)
bb = sorted(B,key=lambda x: -x)
ans = 0
I = H
for x in bb:
  I = I - x
  ans += 1
  if (I <= 0):
    break
if (I > 0):
  ans += math.floor(I/max(aa))
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())
aa = sorted(A,key=lambda x: -x)
bb = sorted(B,key=lambda x: -x)
ans = 0
I = H
mh = max(aa)
for x in bb:
  if (x < mh):
    break
  I = I - x
  ans += 1
  if (I <= 0):
    break
if (I > 0):
  ans += math.ceil(I/max(aa))
print(ans)
Buggy code:
n, h = (int(s) for s in input().split())

a = []
b = []

for i in range(n):
    a_i, b_i = (int(s) for s in input().split())
    a.append(a_i)
    b.append(b_i)

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

for i, b_i in enumerate(b):
    if b_i > a_max:
        h -= b_i
        if h <= 0:
            print(i + 1)
            break
    else:
        print(i + (h - 1) // a_max + 1)
        break
else:
    print(i + (h - 1) // a_max + 1)

Fixed code:
n, h = (int(s) for s in input().split())

a = []
b = []

for i in range(n):
    a_i, b_i = (int(s) for s in input().split())
    a.append(a_i)
    b.append(b_i)

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

for i, b_i in enumerate(b):
    if b_i > a_max:
        h -= b_i
        if h <= 0:
            print(i + 1)
            break
    else:
        print(i + (h - 1) // a_max + 1)
        break
else:
    print(len(b) + (h - 1) // a_max + 1)
Buggy code:
N,H = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    H -= ab[0][1]
    ans += 1
    print(ab)
    ab.pop(0)
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N-1):
      if ab[i][1] < swing:
          continue
      H -= ab[i][1]
      ans += 1
      if H <= 0:
          break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)


Fixed code:
N,H = map(int,input().split());
ab = [list(map(int,input().split())) for _ in range(N)]
ab.sort(key = lambda x:x[0],reverse = True)
swing = ab[0][0]
ans = 0
if H<= ab[0][1]:
    print(1)
else:
    ab.sort(key = lambda x:x[1],reverse = True)
    for i in range(N):
        if ab[i][1] >= swing:
          H -= ab[i][1]
          ans += 1 
        else:
            continue
        if H <= 0:
            break
    else:
        if H % swing == 0:
            ans += H//swing
        else:
            ans += H//swing +1
    print(ans)
Buggy code:
n, h = map(int, input().split())
katana = []
attacker = 0

for _ in range(n):
    array = list(map(int, input().split()))
    katana.append(array)
    if array[0] > attacker:
        attacker = array[0]

katana.sort(key=lambda x:x[1], reverse=True)

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

ans += h // attacker

print(ans)



Fixed code:
from math import ceil


n, h = map(int, input().split())
katana = []
attacker = 0

for _ in range(n):
    array = list(map(int, input().split()))
    katana.append(array)
    if array[0] > attacker:
        attacker = array[0]

katana.sort(key=lambda x:x[1], reverse=True)

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

ans += ceil(h/attacker)

print(ans)
Buggy code:
import sys
from operator import itemgetter
input=sys.stdin.readline
n,x=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
a=list(zip(*a))
t=max(a[0])
a.sort(key=itemgetter(1),reverse=True)
ans=0
for i in range(n):
  if x<=0:
    print(ans)
    break
  if a[1][i]>=t:
    x-=a[1][i]
    ans+=1
  else:
    ans+=(x+t-1)//t
    x=0

Fixed code:
import sys
from operator import itemgetter
input=sys.stdin.readline
n,x=map(int,input().split())
a=[list(map(int,input().split())) for i in range(n)]
b=list(zip(*a))
t=max(b[0])
a.sort(key=itemgetter(1),reverse=True)
ans=0
for i in range(n):
  if a[i][1]>=t:
    x-=a[i][1]
    ans+=1
  if x<=0:
    print(ans)
    break
else:
  ans+=(x+t-1)//t
  x=0
  print(ans)
Buggy code:
n, h = map(int, input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
x=0
a_list = [e[i][0] for i in range(n)]
t_list = [e[i][1] for i in range(n)]
a=max(a_list)
t_list=sorted((i for i in t_list if i >a),reverse=True)
if h>sum(t_list):
  h=h-sum(t_list)
  x=len(t_list)+(-(-h//a))
else:
  for i in range(n):
    h=h-t_list[i]
    if h<=0:
      break
    else:
      x=x+1
print(x)

Fixed code:
n, h = map(int, input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 
x=0
a_list = [e[i][0] for i in range(n)]
t_list = [e[i][1] for i in range(n)]
a=max(a_list)
t_list=sorted((i for i in t_list if i >a),reverse=True)
if h>sum(t_list):
  h=h-sum(t_list)
  x=len(t_list)+(-(-h//a))
else:
  for i in range(len(t_list)):
    h=h-t_list[i]
    x=x+1
    if h<=0:
      break 
print(x)
Buggy code:
n, h = list(map(int, input().split()))
a = [0 for i in range(n)]
b = [0 for i in range(n)]
for i in range(n):
    a[i], b[i] = list(map(int, input().split()))
f = max(a)
b.sort()
for i in range(n):
    if b[i] <= f:
        b[i] = 0
    else:
        break

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


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

total = 0
count = 0
b.reverse()
for i in range(n):
    if b[i] == 0:
        break
    total += b[i]
    count += 1
    if total >= h:
        print(count)
        exit()
if (h - total) % f == 0:
    count += (h - total) // f
else:
    count += (h - total) // f
    count += 1
print(count)
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())
A.sort(reverse=True)
B.sort(reverse=True)

c = 0
for j in range(n):
  if B[j] >= A[0]:
    c += 1
    h -= B[j]
    if h < 0:
      print(c)
      exit()
  else:
    break
if h%A[0] == 0:
  c += h//A[0]
else:
  c = h//A[0]+1
print(c)



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

c = 0
for j in range(n):
  if B[j] >= A[0]:
    c += 1
    h -= B[j]
    if h <= 0:
      print(c)
      exit()
  else:
    break
if h%A[0] == 0:
  c += h//A[0]
else:
  c += h//A[0]+1
print(c)
Buggy code:
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:
        H -= bigb
        b.remove(bigb)
        bigb = b[0]
    else:
        H -= biga
    count += 1

print(count)

Fixed code:
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)
Buggy code:
import bisect
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)
atk = max(A)
B.sort(reverse=True)
L = [0]
for i in range(n-1):
    if B[i] >= atk:
        L.append(L[-1] + B[i])
    else:
        break
if L[-1] >= h:
        ans = bisect.bisect_left(L, h)
else:
    h -= L[-1]
    ans = len(L) - 1 + math.ceil(h / atk)
print(ans)


Fixed code:
import bisect
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)
atk = max(A)
B.sort(reverse=True)
L = [0]
for i in range(n):
    if B[i] >= atk:
        L.append(L[-1] + B[i])
    else:
        break
if L[-1] >= h:
        ans = bisect.bisect_left(L, h)
else:
    h -= L[-1]
    ans = len(L) - 1 + math.ceil(h / atk)
print(ans)
Buggy code:
def solve():
    N,H = list(map(int, input().split()))
    az = []
    bz = []
    for i in range(N):
        a,b = list(map(int, input().split()))
        az.append(a)
        bz.append(b)
        
    amax = max(az)
    bz.sort(reverse=True)
    cnt = 0
    for b in bz:
        if amax < b:
            H -= b
            cnt += 1
        if H <= 0:
            return cnt
    if H <= 0:
        return cnt
    
    cnt += int(H/a)
    cnt += (1 if H % a != 0 else 0)
    return cnt
        
print(solve())

Fixed code:
def solve():
    N,H = list(map(int, input().split()))
    az = []
    bz = []
    for i in range(N):
        a,b = list(map(int, input().split()))
        az.append(a)
        bz.append(b)
        
    amax = max(az)
    bz.sort(reverse=True)
    cnt = 0
    for b in bz:
        if amax < b:
            H -= b
            cnt += 1
        if H <= 0:
            return cnt
    if H <= 0:
        return cnt
    cnt += int(H / amax)
    cnt += min(H % amax, 1)
    return cnt
        
print(solve())
Buggy code:
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--H//M
ans+=1
print(ans)

Fixed code:
N,H=map(int,input().split())
ab=[list(map(int,input().split()))for _ in range(N)]
ab.sort()
M=ab[-1][0]
B=[b for a,b in ab]
B.sort()
B=B[::-1]
ans=0
for b in B:
    if H>0 and b>M:
        H-=b
        ans+=1
    else:
        break
ans+=0--max(0,H)//M
print(ans)
Buggy code:
n, h = map(int, input().split())
arr_a = []
arr_b = []
for _ in range(n):
    a, b = map(int, input().split())
    arr_a.append(a)
    arr_b.append(b)

max_a = max(arr_a)
arr_b.sort(reverse=True)

ans = 0
for b in arr_b:
    ans += 1
    h -= b
    if h <= 0:
        break
else:
    ans += 0 - -h//max_a

print(ans)


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

max_a = max(arr_a)
arr_b.sort(reverse=True)

ans = 0
for b in filter(lambda x: x > max_a, arr_b):
    ans += 1
    h -= b
    if h <= 0:
        break
else:
    ans += 0 - -h//max_a

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
i=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    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
i=0
for i in range(len(C)):
    if ans<h:
        ans+=C[i]
    else:
        break
    cnt+=1
if ans<h:
    if ((h-ans)//amax)*amax>=h-ans:
        cnt+=(h-ans)//amax
    else:
        cnt+=(h-ans)//amax+1
        
print(cnt)
Buggy code:
import math

n, h = [int(i) for i in input().split(" ")]
t = []

for i in range(0, n):
    a, b = [int(i) for i in input().split(" ")]
    t.append((a, "a"))
    t.append((b, "b"))

t = sorted(t, key=lambda k: k[0], reverse=True)

print(t)

c = 0
i = 0

while h > 0:
    if t[i][1] == "b":
        h -= t[i][0]
        c += 1
        i += 1
    else:
        c += math.ceil(h / t[i][0])
        h = 0

print(c)

Fixed code:
import math

n, h = [int(i) for i in input().split(" ")]
t = []

for i in range(0, n):
    a, b = [int(i) for i in input().split(" ")]
    t.append((a, "a"))
    t.append((b, "b"))

t = sorted(t, key=lambda k: k[0], reverse=True)

c = 0
i = 0

while h > 0:
    if t[i][1] == "b":
        h -= t[i][0]
        c += 1
        i += 1
    else:
        c += math.ceil(h / t[i][0])
        h = 0

print(c)
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())
b.sort(reverse=True)
a.sort(reverse=True)
cnt=0
for i in range(N):
    H=H-b[i]
    cnt+=1
    if H<=0:
        break

if H>0:
    if H%a[0]==0:
        cnt+=H//a[0]
    else:
        cnt+=H//a[0]+1
print(cnt)

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())
b.sort(reverse=True)
a.sort(reverse=True)
cnt=0
for i in range(N):
    if b[i]>=a[0]:
        H=H-b[i]
        cnt+=1
    if H<=0:
        break

if H>0:
    if H%a[0]==0:
        cnt+=H//a[0]
    else:
        cnt+=H//a[0]+1
print(cnt)
Buggy code:
n, h = map(int, input().split())
katana = [list(map(int, input().split())) for i in range(n)]

th_sum = 0
for i in range(n):
    th_sum += katana[i][1]

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

    count = n - 1
    h -= (th_sum + katana[sw_i][0] - katana[sw_i][1])
    if h % sw_max == 0:
        count += h//sw_max
    else:
        count += h//sw_max + 1
    print(count)

Fixed code:
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)
Buggy code:
N, H = tuple(map(int, input().split(' ')))
katanas = [list(map(int, input().split(' '))) for _ in range(0, N)]

normaldmbs = list(map(lambda x: x[0], katanas))
max_normal_dmg = max(normaldmbs)

throwables = list(map(lambda x: x[1], filter(lambda x: x[1] > max_normal_dmg, katanas)))
throwables.sort().reverse()

cnt = 0

for v in throwables:
    H -= v
    cnt += 1
    if H <= 0:
        break

if H > 0:
    if H % max_normal_dmg == 0:
        cnt += int(H / max_normal_dmg)
    else:
        cnt += int(H / max_normal_dmg) + 1


print(cnt)

Fixed code:
N, H = tuple(map(int, input().split(' ')))
katanas = [list(map(int, input().split(' '))) for _ in range(0, N)]

normaldmbs = list(map(lambda x: x[0], katanas))
max_normal_dmg = max(normaldmbs)

throwables = list(map(lambda x: x[1], filter(lambda x: x[1] > max_normal_dmg, katanas)))
throwables.sort(reverse=True)

cnt = 0

for v in throwables:
    H -= v
    cnt += 1
    if H <= 0:
        break

if H > 0:
    if H % max_normal_dmg == 0:
        cnt += int(H / max_normal_dmg)
    else:
        cnt += int(H / max_normal_dmg) + 1


print(cnt)