Buggy python submission (verdict: Runtime Error):

N, H = map(int, input().split())
A = []
B = []

max_a = 0
max_a_b = 0
max_a_i = 0

max_b = 0
max_b_a = 0
max_b_i = 0

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

    if max_a < a:
        max_a = a
        max_a_b = b
        max_a_i = i

    if max_b < b:
        max_b = b
        max_b_a = a
        max_b_i = i

def get_count(N, H, max_a, max_a_b, max_a_i):
    count = 0
    for i in range(N):
        # 残すやつは何もしない
        if i == max_a_i:
            continue

        # 投げる
        if B[i] >= max_a:
            H -= B[i]
            count += 1

    # 近いところまでまとめて引く
    x = ((H-max_a_b) // max_a) - 1
    H -= (max_a * x)
    count += x

    while H > 0:
        if H <= max_a_b:
            # 投げて終わり
            count += 1
            break

        H -= max_a
        count += 1

    return count

ans = INF
count = get_count(N, H, max_a, max_a_b, max_a_i)
if count < ans:
    ans = count

count = get_count(N, H, max_b_a, max_b, max_b_i)
if count < ans:
    ans = count

print(ans)


Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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)

max_a = max(A)

t = B[:]
t.sort(reverse=True)

count = 0
for i in range(N):
    # 先に投げても後で投げても同じなので、最初に全部投げちゃう
    # ただし強いものから投げないと、投げ終わる前に倒すケースで引っかかる
    if t[i] >= max_a:
        H -= t[i]
        count += 1

    if H <= 0:
        print(count)
        exit()


# 近いところまでまとめて引く
x = (H // max_a) - 1
H -= (max_a * x)
count += x

while H > 0:
    H -= max_a
    count += 1


print(count)

Buggy python submission (verdict: Time Limit Exceeded):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

"""
基本
・max(A)以上の(B)を全部投げちゃう
・max(A)をひたすら振って、残りHP <= B の時点で投げて終わり

ただし、どれを残すべきかは確定しないので全探索
"""

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

#    if max_a < a:
#        max_a = a
#        max_a_b = b
#        max_a_i = i


def get_count(N, H, max_a, max_a_b, max_a_i):
    count = 0
    for i in range(N):
        # 残すやつは何もしない
        if i == max_a_i:
            continue

        # 投げる
        if B[i] >= max_a:
            H -= B[i]
            count += 1

    # 近いところまでまとめて引く
    x = ((H-max_a_b) // max_a) - 1
    H -= (max_a * x)
    count += x

    while H > 0:
        if H <= max_a_b:
            # 投げて終わり
            count += 1
            break

        H -= max_a
        count += 1

    return count

ans = INF
for i in range(N):
    count = get_count(N, H, A[i], B[i], i)
    if count < ans:
        ans = count

print(ans)


Fixed submission:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# A = [ int(input()) for _ in range(N) ]
##############################

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)

max_a = max(A)

t = B[:]
t.sort(reverse=True)

count = 0
for i in range(N):
    # 先に投げても後で投げても同じなので、最初に全部投げちゃう
    # ただし強いものから投げないと、投げ終わる前に倒すケースで引っかかる
    if t[i] >= max_a:
        H -= t[i]
        count += 1

    if H <= 0:
        print(count)
        exit()


# 近いところまでまとめて引く
x = (H // max_a) - 1
H -= (max_a * x)
count += x

while H > 0:
    H -= max_a
    count += 1


print(count)