qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N, H = map(int, input().split())
ab = [[int(i) for i in input().split()] for _ in range(N)]

a = 0
for i in range(N):
    a = max(a, ab[i][0])

b = []
for i in range(N):
    if ab[i][1] > a:
        b.append(ab[i][1])
b.sort(reverse=True)

c = 0
h = H
for i in range(len(b)):
    h -= b[i]
    c += 1
    if h <= 0:
        print(c)
        break

print(c + (h-1)//a + 1)


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

a = 0
for i in range(N):
    a = max(a, ab[i][0])

b = []
for i in range(N):
    if ab[i][1] > a:
        b.append(ab[i][1])
b.sort(reverse=True)

w = True
c = 0
h = H
for i in range(len(b)):
    h -= b[i]
    c += 1
    if h <= 0:
        print(c)
        w = False
        break

if w:
    print(c + (h-1)//a + 1)
Buggy code:
import sys

n, h = map(int, input().split())
a = []
b = []

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

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

b = [x for x in b if x > max_a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

ans = i + 1 + h // max_a

print(ans)

Fixed code:
import sys
import math

n, h = map(int, input().split())
a = 0
b = []

for i in range(n):
    x, y = map(int, input().split())
    a = max(a, x)
    b.append(y)

b.sort(reverse=True)

b = [x for x in b if x > a]

for i, x in enumerate(b):
    h -= x
    if h <= 0:
        print(i + 1)
        sys.exit()

if len(b) == 0:
    i = -1

ans = i + 1 + math.ceil(h / a)

print(ans)
Buggy code:
from bisect import bisect_left
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 = max(A)
B = sorted(B)

damage = 0
count = 0
b = bisect_left(B,A)
damage = sum(B[b:])
count += len(B[b:])
if (H-damage)//A >= 1:
  count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)

Fixed code:
from bisect import bisect_left
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 = max(A)
B = sorted(B)

count,damage = 0,0
b = bisect_left(B,A)

for i in range(len(B)-1,b-1,-1):
  damage += B[i]
  count += 1
  if damage >= H:
    print(count)
    exit()

count,damage = 0,0
damage = sum(B[b:])
count += len(B[b:])
count += (H-damage)//A
damage = H - (H-damage)%A
if damage == H:
  pass
else:
  count += 1
print(count)
Buggy code:
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    if H < 0:
        break
    cnt += 1
    ans = min(ans, cnt + ceil(H/atop))
print(ans)

Fixed code:
# coding: utf-8
from math import ceil
N, H = map(int, input().split())
li = []
atop = 0
for _ in range(N):
    a, b = map(int, input().split())
    atop = max(atop, a)
    li.append([a, b])
li.sort(key=lambda x: x[1], reverse=True)
# print(li)
ans = ceil(H/atop)
cnt = 0
for i in range(N):
    H -= li[i][1]
    cnt += 1
    ans = min(ans, cnt + max(0, ceil(H/atop)))
print(ans)
Buggy code:
import math

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

score = 0
for i in range(N):
    if B[i] <= A[0]:
        break
    score += B[i]
    if score >= H:
        print(i + 1)
        exit()

print(math.ceil((H - score) / A[0]) + i)


Fixed code:
import math

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

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

print(math.ceil((H - score) / A[0]) + i + 1)
Buggy code:
n, h = map(int, input().split())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, "a"))
    ab.append((b, "b"))

ab.sort(reverse=True, key=lambda x: x[0])
print(ab)
count = 0
for x, y in ab:
    if h <= 0:
        break
    if y == "a":
        if h%x == 0:
            count += h//x
            h = 0
        else:
            count += h//x + 1
            h = 0
    if y == "b":
        h -= x
        count += 1

print(count)

Fixed code:
n, h = map(int, input().split())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    ab.append((a, "a"))
    ab.append((b, "b"))

ab.sort(reverse=True, key=lambda x: x[0])
#print(ab)
count = 0
for x, y in ab:
    if h <= 0:
        break
    if y == "a":
        if h%x == 0:
            count += h//x
            h = 0
        else:
            count += h//x + 1
            h = 0
    if y == "b":
        h -= x
        count += 1

print(count)
Buggy code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append((a,b))
cand = []
throw = 0
cnt = 0
for l in L:
    if maxi <  l[1]:
        throw += l[1]
        cand.append(l[1])
        cnt += 1
import math
print(cand)
if H - throw > 0: 
    print(math.ceil((H - throw)/maxi) + cnt )
else:
    throw = 0
    cnt = 0
    cand.sort()
    for x in cand[::-1]:
        throw += x
        cnt += 1
        if throw >= H:
            print(cnt)



Fixed code:
N, H = map(int,input().split())
L = []
maxi = 0
for _ in range(N):
    a,b = map(int,input().split())
    maxi = max(maxi, a)
    L.append((a,b))
cand = []
throw = 0
cnt = 0
for l in L:
    if maxi <  l[1]:
        throw += l[1]
        cand.append(l[1])
        cnt += 1
import math
if H - throw > 0: 
    print(math.ceil((H - throw)/maxi) + cnt )
else:
    throw = 0
    cnt = 0
    cand.sort()
    for x in cand[::-1]:
        throw += x
        cnt += 1
        if throw >= H:
            print(cnt)
            quit()
Buggy code:

import math

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

B.sort(reverse=True)

accum_B = [0] * (N+1)
for i in range(1, N+1):
  accum_B[i] = accum_B[i-1] + B[i-1]

ans = H+1
for i in range(N+1):
  if H - accum_B[i] <= 0:
    sns = min(ans, i)
  else:
    ans = min(ans, i + math.ceil((H - accum_B[i]) / A))

print(ans)


Fixed code:

import math

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

B.sort(reverse=True)

accum_B = [0] * (N+1)
for i in range(1, N+1):
  accum_B[i] = accum_B[i-1] + B[i-1]

ans = H+1
for i in range(N+1):
  if H - accum_B[i] <= 0:
    ans = min(ans, i)
  else:
    ans = min(ans, i + math.ceil((H - accum_B[i]) / A))

print(ans)
Buggy code:
from operator import itemgetter
n,h = map(int,input().split())

info = [list(map(int,input().split())) for i in range(n)]

maxFuru = max(list(zip(*info))[0])

nageru = []
for i in range(n):
  if info[i][1] > maxFuru:
    nageru.append(info[i][1])
nageru = sorted(nageru)

nokori = h
ans = 0

while nokori>0:
  if nageru:
    nokori -= nageru[-1]
    del nageru[-1]
    ans += 1
  else:
    ans += -(-nokori)//maxFuru
    nokori = 0

print(ans)

Fixed code:
from operator import itemgetter
n,h = map(int,input().split())

info = [list(map(int,input().split())) for i in range(n)]

maxFuru = max(list(zip(*info))[0])


nageru = []
for i in range(n):
  if info[i][1] > maxFuru:
    nageru.append(info[i][1])
nageru = sorted(nageru)

nokori = h
ans = 0

while nokori>0:
  if nageru:
    nokori -= nageru[-1]
    del nageru[-1]
    ans += 1
  else:
    ans += -((-nokori)//maxFuru)
    nokori = 0

print(ans)
Buggy code:
n, h = map(int, input().split())
katana = [tuple(map(int, input().split())) for _ in range(n)]
maxa = 0
for a, _ in katana:
    maxa = max(maxa, a)
bgreedy = 0
count = 0
katana.sort(lambda x: x[1], reverse = True)
for a, b in katana:
    if b < maxa:
        break
    bgreedy += b
    count += 1
    if h <= bgreedy:
        print(count)
        exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))

Fixed code:
n, h = map(int, input().split())
katana = [tuple(map(int, input().split())) for _ in range(n)]
maxa = 0
for a, _ in katana:
    maxa = max(maxa, a)
bgreedy = 0
count = 0
katana.sort(key = lambda x: x[1], reverse = True)
for a, b in katana:
    if b < maxa:
        break
    bgreedy += b
    count += 1
    if h <= bgreedy:
        print(count)
        exit()
print(count + (h - bgreedy)//maxa + int((h-bgreedy) % maxa != 0))
Buggy code:
N,H = map(int,input().split())
Ma = 1
B = []
for i in range(N):
    a,b = map(int,input().split())
    B.append(b)
    if a > Ma:
        Ma = a
B.sort()
B.reverse()
i = 0
Mb = B[0]
while Mb > Ma:
  i += 1
  if i == N:
    Mb = 0
    B = B[:i]
  else:
    Mb = B[i]
H -= sum(B)
print(i+int(-(-H//Ma)))

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

for i in range(n):
    if a<x[i][0]:
        a=x[i][0]

for i in range(n):
    if a<x[i][1]:
        b.append(x[i][1])
        
b.sort()
b.reverse()

for i in range(len(b)):
    h-=b[i]
    if h<=0:
        print(i+1)
        exit()
        
v=h-sum(b)
w=-(-v//a)
print(w+len(b))
    

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

for i in range(n):
    if a<x[i][0]:
        a=x[i][0]

for i in range(n):
    if a<x[i][1]:
        b.append(x[i][1])
        
b.sort()
b.reverse()

for i in range(len(b)):
    h-=b[i]
    if h<=0:
        print(i+1)
        exit()
        
w=-(-h//a)
print(w+len(b))
Buggy code:
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)

b = [b[j] for j in range(n) if b[j] > amax]
sumb = sum(b)
if sumb >= h:
  s = 0
  b = sorted(b)
  c = 0
  while s < h:
    s += b[-1]
    b.pop(-1)
    c + =1
  print(c)
else:
  print((h-sumb)//amax+((h-sumb)%amax!=0) + len(b))



Fixed code:
n, h = map(int, input().split())
a = []
b = []
amax = 0
for i in range(n):
  ai, bi = map(int, input().split())
  if amax < ai:
    amax = ai
  a.append(ai)
  b.append(bi)

b = [b[j] for j in range(n) if b[j] > amax]
sumb = sum(b)
if sumb >= h:
  s = 0
  b = sorted(b)
  c = 0
  while s < h:
    s += b[-1]
    b.pop(-1)
    c += 1
  print(c)
else:
  print((h-sumb)//amax+((h-sumb)%amax!=0) + len(b))
Buggy code:
N, HP = map(int, input().split())

K = []
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  B.append(b)
  A.append(a)
  
MA = max(A)
ans = 0
for b in sorted(B, reverse=True):
  HP -= b
  ans += 1
  if HP <= 0:
    exit()
    
  if MA > b:
    break

ans += HP // MA
print(ans)

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

K = []
A = []
B = []
for _ in range(N):
  a, b = map(int, input().split())
  B.append(b)
  A.append(a)
  
MA = max(A)
ans = 0
for b in sorted(B, reverse=True):
  if MA > b:
    break
  HP -= b
  ans += 1
  if HP <= 0:
    print(ans)
    exit()

c = HP // MA
ans += c

if HP - (c*MA) > 0:
  ans += 1

print(ans)
Buggy code:
import bisect
from math import ceil

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

a = [0]*N
b = [0]*N

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

a_max = max(a)

ans = 0
b.sort()
a.sort()
damage = 0
while damage < H:
  if b[-1] > a_max:
    damage += b.pop()
    ans += 1
  else:
    ans += ceil((H-damage)/a[-1])
    damage = H
print(ans)


Fixed code:
import bisect
from math import ceil

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

a = [0]*N
b = [0]*N

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

a_max = max(a)

ans = 0
b.sort()
a.sort()
damage = 0
while damage < H:
  if len(b) >= 1 and b[-1] > a_max:
    damage += b.pop()
    ans += 1
  else:
    ans += ceil((H-damage)/a[-1])
    damage = H
print(ans)
Buggy code:
from math import ceil
n,h = (int(i) for i in input().split())
a = []
b = [0]
for i in range(n):
 tmp1,tmp2= (int(i) for i in input().split())
 a.append(tmp1)
 b.append(tmp2)
a2 = sorted(a,reverse = True)
b2 = sorted(b,reverse = True)

count  = 0
while h > 0:
  if a2[0] > b2[0]:
    tmp3 = ceil(h/a2[0])
    count += tmp3
    h -= tmp3
  else:
    count += 1
    h -= b2[0]
    b2.pop(0)
print(count)

Fixed code:
import math
n,h = (int(i) for i in input().split())
a = []
b = [0]
for i in range(n):
 tmp1,tmp2= (int(i) for i in input().split())
 a.append(tmp1)
 b.append(tmp2)
a2 = sorted(a,reverse = True)
b2 = sorted(b,reverse = True)

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


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

for i in range(n):
    if b[i] > a_big:
        bi_str.append(b[i])
bi_str.sort(reverse=True)
print(bi_str)
if h <= sum(bi_str):
    for i in bi_str:
        if h > 0:
            h -= i
            ans += 1
        else:
            break
else:
    h -= sum(bi_str)
    ans += len(bi_str)
    if round(h/a_big) == h//a_big:
        ans += h//a_big
    else:
        ans += h//a_big+1

print(ans)

Fixed code:
n, h = map(int, input().split())
bi_str = []
a_big = 0
ans = 0
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = map(int, input().split())
    if a[i] > a_big:
        a_big = a[i]

for i in range(n):
    if b[i] > a_big:
        bi_str.append(b[i])
bi_str.sort(reverse=True)
#print(bi_str)
#print(a_big)
if h <= sum(bi_str):
    for i in bi_str:
        if h > 0:
            h -= i
            ans += 1
        else:
            break
else:
    h -= sum(bi_str)
    ans += len(bi_str)
    ans += -(-h//a_big)
    '''
    if round(h/a_big) == h//a_big:
        ans += h//a_big
    else:
        ans += h//a_big+1
        '''

print(ans)
Buggy code:
# ABC85 D 
import math

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    for b in b_list:
        if b < a:
            break
        H -= b
        cnt += 1
    
    print(cnt + math.ceil(H / a_max))

if __name__ == "__main__":
    main()


Fixed code:
# ABC85 D 
import math

def main():
    N, H = list(map(int, input().split()))
    a_max = 0
    b_list = []

    for _ in range(N):
        a,b = list(map(int, input().split()))
        a_max = max(a, a_max)
        b_list.append(b)

    b_list = sorted(b_list)[::-1]
    
    cnt = 0
    for b in b_list:
        if b < a_max:
            break
        if H <= 0:
            break
        H -= b
        cnt += 1
    
    if H > 0:
        print(cnt + math.ceil(H / a_max))
    else:
        print(cnt)

if __name__ == "__main__":
    main()
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)

alist = sorted(alist)[::-1]
blist = sorted(blist)[::-1]

ans = 0
i = 0

while i < len(blist):
  h -= blist[i]
  ans += 1
  if h <= 0:
    print(ans)
    exit()  
  i += 1

if h % alist[0] == 0:
  ans += h // alist[0]
  print(ans)
else:
  ans += (h // alist[0]) + 1
  print(ans)

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)

alist = sorted(alist)[::-1]
blist = sorted(blist)[::-1]

ans = 0
i = 0

while i < len(blist):
  if alist[0] >= blist[i]:
    break
  h -= blist[i]
  ans += 1
  if h <= 0:
    print(ans)
    exit()  
  i += 1

if h % alist[0] == 0:
  ans += h // alist[0]
  print(ans)
else:
  ans += (h // alist[0]) + 1
  print(ans)
Buggy code:
import math
n, h = map(int, input().split())
max_swing = 0
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    max_swing = max(max_swing, a)
    throw.append(b)

throw.sort(reverse=true)

min_cnt = int(math.ceil(h / max_swing))
throw_cnt = 0
for t in throw:
    h -= t
    throw_cnt += 1
    if h <= 0:
        min_cnt = min(throw_cnt, min_cnt)
        break
    cnt = throw_cnt + int(math.ceil(h / max_swing))
    min_cnt = min(cnt, min_cnt)

print(min_cnt)


Fixed code:
import math
n, h = map(int, input().split())
max_swing = 0
throw = []
for _ in range(n):
    a, b = map(int, input().split())
    max_swing = max(max_swing, a)
    throw.append(b)

throw.sort(reverse=True)

min_cnt = int(math.ceil(h / max_swing))
throw_cnt = 0
for t in throw:
    h -= t
    throw_cnt += 1
    if h <= 0:
        min_cnt = min(throw_cnt, min_cnt)
        break
    cnt = throw_cnt + int(math.ceil(h / max_swing))
    min_cnt = min(cnt, min_cnt)

print(min_cnt)
Buggy code:
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = 0
H_ = H
flag = True
for j in sorted(throw_l)[::-1]:
    H_ -= j
    if H_ < 0:
        flag = False
        break
    ans += 1
if flag:
    ans = (H - sum(throw_l))/swing_m
    ans = math.ceil(ans)
    print(ans+len(throw_l))
else:
    print(ans)

Fixed code:
from sys import stdin
import math
N,H = [int(x) for x in stdin.readline().rstrip().split()]
swing = []
throw = []
for _ in range(N):
    a,b = [int(x) for x in stdin.readline().rstrip().split()]
    swing.append(a)
    throw.append(b)
swing_m = max(swing)
throw_l = [i for i in throw if i >= swing_m]
ans = 0
H_ = H
flag = True
for j in sorted(throw_l)[::-1]:
    H_ -= j
    ans += 1
    if H_ <= 0:
        flag = False
        break
if flag:
    ans = (H - sum(throw_l))/swing_m
    ans = math.ceil(ans)
    print(ans+len(throw_l))
else:
    print(ans)
Buggy code:
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)
  
b_list = sorted(b_list)

count = 0
a_max = max(a_list)

while H > 0:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)



Fixed code:
N, H = map(int, input().split())
a_list = []
b_list = []
for _ in range(N):
  a, b = map(int, input().split())
  a_list.append(a)
  b_list.append(b)
  
b_list = sorted(b_list)

count = 0
a_max = max(a_list)

while H > 0 and b_list:
  b = b_list.pop()
  if b > a_max:
    H -= b
    count += 1
  else:
    break
    
if H > 0:
  if H % a_max == 0:
    count += H // a_max
  else:
    count += H // a_max + 1
    
print(count)
Buggy code:
N,M = map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

count = 0
for i in range(N):
	if a <= X[i][1]:
		M -= X[i][1]
		count += 1
		if M <= 0:
			break

print(M,count)
if M > 0:
	count += -((-M)//a)
else:
	count += 1

print(count)

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

X = [list(map(int,input().split())) for _ in range(N)]
X = sorted(X,key=lambda X:-X[0])
a = X[0][0]
X = sorted(X,key=lambda X:-X[1])

i = 0
count = 0
while M > 0:
	if i < N and X[i][1] > a:
		M -= X[i][1]
		i += 1
	else:
		count += -(-M//a)
		break
	count += 1

print(count)
Buggy code:
import math
n,h = map(int,input().split())
al = []
bl = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    al += [a]
    bl += [b]
am = max(al)
bl.sort(reverse=1)
print(al)
print(bl)
for i in bl:
    if i>am:
        ans += 1
        h -= i
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += math.ceil(h/am)
print(ans)

Fixed code:
import math
n,h = map(int,input().split())
al = []
bl = []
ans = 0
for i in range(n):
    a,b = map(int,input().split())
    al += [a]
    bl += [b]
am = max(al)
bl.sort(reverse=1)
for i in bl:
    if i>am:
        ans += 1
        h -= i
        if h <= 0:
            break
    else:
        break
if h > 0:
    ans += math.ceil(h/am)
print(ans)
Buggy code:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N-1):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
else:
  n = H//a[0] if H%a[0]==0 else H//a[0]+1
  ans += n
  print(ans)

Fixed code:
N, H = map(int, input().split())
ls = []
for i in range(N):
  a, b = map(int, input().split())
  ls += [(a,-b)]
ls.sort(key=lambda x:x[0])
a = ls[-1][0]
ls.sort(key=lambda x:x[1])
ans = 0
for i in range(N):
  if ls[i][1]>=-a:
    break
  H += ls[i][1]
  ans += 1
  if H<=0:
    print(ans)
    break
if H>0:
  n = H//a if H%a==0 else H//a+1
  ans += n
  print(ans)
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 = sorted(a, reverse=True)
b = sorted(b, reverse=True)

count = 0
while True:
    if h <= 0:
        break
    elif b[0] <= a[0]:
        count += -(- h // a[0])
        break
    else:
        h -= b.pop(0)
        count += 1

print(count)

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)
b.append(0)
a2 = sorted(a, reverse=True)
b2 = sorted(b, reverse=True)

count = 0
while True:
    if h <= 0:
        break
    elif b2[0] <= a2[0]:
        count += -(- h // a2[0])
        break
    else:
        h -= b2.pop(0)
        count += 1

print(count)
Buggy code:
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B.sort(reversed=True)
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))

Fixed code:
N, H = list(map(int, input().split()))
A = [0]*N
B = [0]*N
for i in range(N):
    a, b = list(map(int, input().split()))
    A[i], B[i] = a, b
a = max(A)
T = 0
ct = 0
B = reversed(sorted(B))
for b in B:
    if b > a:
        ct += 1
        T += b
    if T >= H:
        break
print(ct + max((H-T+a-1)//a, 0))