Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.buffer.readline
 
h,n = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(n)]

inf=float("inf")
dp=[inf]*(h+1)
 
dp[0]=0

for a,b in AB:
    for i in range(h):
        if dp[i]!=float("inf"):
            dp[min(i+a,h)]=min(dp[min(i+a,h),dp[i]+b])
print(dp[-1])
            

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
 
h, n = map(int, input().split())
A = []
B = []
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
  
dp=[float("inf")]*h
dp[0]=0
answer = float("inf")

for i in range(h+1):
    for j in range(n):
      if i + A[j] < h:
        dp[i+A[j]]=min(dp[i+A[j]],dp[i]+B[j])
      else:
        answer = min(answer, dp[i]+B[j])
print(answer)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

h, n = map(int, input().split())
A = []
B = []
for i in range(n):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)

Ama = max(A)

dp=[float("inf")]*(h+Ama)
dp[0]=0

for i in range(n):
    for j in range(A[i],h+Ama+1):
        dp[j]=min(dp[j],dp[j-A[i]+B[i]])
print(min(dp[h:]))

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

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

dp=[float("inf")]*(2*10000+1)
dp[0]=0

for i in range(h):
    for j in range(n):
        if (i+a[j])>2*10000:
            dp[2*10000]=min(dp[2*10000],dp[i]+b[j])
            continue
        dp[i+a[j]]=min(dp[i+a[j]],dp[i]+b[j])

ans=float("inf")
for j in range(h,2*10000+1):
    ans=min(ans,dp[j])
print(ans)
    
            


Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)

Fixed submission:
h, n = map(int, input().split())
a = []
b = []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
 
dp = [float("inf")] * (2 * 10000 + 1)
dp[0] = 0
for i in range(h):
    for j in range(n):
        if (i + a[j]) > 2 * 10000:
            dp[2 * 10000] = min(dp[2 * 10000], dp[i] + b[j])
            continue
        dp[i + a[j]] = min(dp[i + a[j]], dp[i] + b[j])
 
ans = float('inf')
for j in range(h, 2 * 10000 + 1):
    ans = min(ans, dp[j])
print(ans)