Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))

Fixed submission:
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
h, n = map(int, input().split())
dp = np.zeros((n+1, h+1))
dp[0] = np.inf
for i in range(1, n+1):
    a, b = map(int, input().split())
    for j in range(1, h+1):
        if j >= a:
            dp[i][j] += min(
                dp[i-1][j], dp[i][j-a] + b,
            )
        else:
            dp[i][j] += min(
                dp[i-1][j], b
            )
print(int(dp[n][h]))


Fixed submission:
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
h, n = map(int, input().split())
dp = np.zeros((n+1, h+1))
dp[0] = np.inf
for i in range(1, n+1):
    a, b = map(int, input().split())
    for j in range(1, h+1):
        if j >= a:
            dp[i][j] += min(
                dp[i-1][j], dp[i][j-a] + b,
            )
        else:
            dp[i][j] += min(
                dp[i-1][j], b
            )
print(int(dp[n][h]))


Fixed submission:
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
h, n = map(int, input().split())
dp = np.zeros((n+1, h+1))
dp[0] = np.inf
for i in range(1, n+1):
    a, b = map(int, input().split())
    for j in range(1, h+1):
        if j >= a:
            dp[i][j] = min(
                dp[i-1][j], dp[i][j-a] + b,
            )
        else:
            dp[i][j] = min(
                dp[i-1][j], b
            )
print(int(dp[n][h]))


Fixed submission:
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))

Buggy python submission (verdict: Runtime Error):
h, n = map(int, input().split())
magic = [
    list(map(int, input().split())) for i in range(n)
]
dp = np.full((n+1, h+1), np.inf, dtype=np.int)
dp[1:, 0] = 0
dp[1][1] = magic[0][0]
for i in range(1, n+1):
    for j in range(1, h + 1):
        if i == 1:
            dp[i][j] = magic[i-1][1] * np.ceil(j/magic[i-1][0])
        elif j >= magic[i-1][0]:
            dp[i][j] = min(
                dp[i-1][j], dp[i][j-magic[i-1][0]] + magic[i-1][1],
            )
        else:
            dp[i][j] = dp[i-1][j]
print(dp[n][h])


Fixed submission:
h, n = map(int, input().split())
inf = 10**11

# dp[i]: 体力iを減らす魔力の最小値
dp = [inf] * 20000
dp[0] = 0

for _ in range(n):
    a, b = map(int, input().split())
    for j in range(h):
        dp[j+a] = min(dp[j] + b, dp[j+a])

print(min(dp[h:]))