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

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

amax = max(a for a,b in ls)

dp = [0]*(h+amax)

for i in range(1,h+amax):
  dp[i] = min(dp[i-a]+b+ 0*max(1,2) for a,b in ls)

print(min(dp[h:]))

Fixed submission:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for i in range(m)]
x=max(a for a,b in s)
dp=[0]*(n+x)
for i in range(0,n+x):
  if i>0:
    dp[i]=min(dp[i-a]+b for a,b in s)
print(min(dp[n:]))

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

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

amax = max(a for a,b in ls)

dp = [0]*(h+amax)

for i in range(1,h+amax):
  dp[i] = min(dp[max(0,i-a)]+b for a,b in ls)

print(min(dp[h:]))



Fixed submission:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for i in range(m)]
x=max(a for a,b in s)
dp=[0]*(n+x)
for i in range(0,n+x):
  if i>0:
    dp[i]=min(dp[i-a]+b for a,b in s)
print(min(dp[n:]))

Buggy python submission (verdict: Time Limit Exceeded):
inf = 10**9

h,n = map(int,input().split())

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

amax = max(a for a,b in ls)

dp = [0]*(h+amax)

for i in range(1,h+amax):
  m = inf
  for a,b in ls:
    tmp = dp[max(0,i-a)] + b
    m = min(m,tmp)
  dp[i] = m

print(min(dp[h:]))



Fixed submission:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for i in range(m)]
x=max(a for a,b in s)
dp=[0]*(n+x)
for i in range(0,n+x):
  if i>0:
    dp[i]=min(dp[i-a]+b for a,b in s)
print(min(dp[n:]))

Buggy python submission (verdict: Time Limit Exceeded):
inf = 10**9

h,n = map(int,input().split())

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

amax = max(a for a,b in ls)

dp = [inf]*(h+amax)
dp[0] = 0

for i in range(1,h+amax):
  m = inf
  for a,b in ls:
    tmp = dp[max(0,i-a)] + b
    m = min(m,tmp)
  dp[i] = m

print(min(dp[h:]))

Fixed submission:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for i in range(m)]
x=max(a for a,b in s)
dp=[0]*(n+x)
for i in range(0,n+x):
  if i>0:
    dp[i]=min(dp[i-a]+b for a,b in s)
print(min(dp[n:]))

Buggy python submission (verdict: Time Limit Exceeded):
h,n = map(int,input().split())
ls = [list(map(int,input().split())) for _ in range(n)]


ls = sorted(ls,key = lambda x: min(x[0],h)/x[1], reverse = True)
ans = 0

t = ls[0]
ans += (h//t[0])*t[1]
h %= t[0]

while h>0:
  ls = sorted(ls,key = lambda x: min(x[0],h)/x[1], reverse = True)
  t = ls[0]
  ans += (h//t[0])*t[1]
  h %= t[0]
print(ans)



Fixed submission:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for i in range(m)]
x=max(a for a,b in s)
dp=[0]*(n+x)
for i in range(0,n+x):
  if i>0:
    dp[i]=min(dp[i-a]+b for a,b in s)
print(min(dp[n:]))

Buggy python submission (verdict: Runtime Error):
from operator import itemgetter, attrgetter

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

for _ in range(n):
  a,b =  map(int,input().split())
  ls.append(a,b)

ls = sorted(ls,key = lambda x: min(x[0],h)/x[1], reverse = True)
ans = 0

t = ls[0]
ans += h//t
h %= t

while h>0:
  ls = sorted(ls,key = lambda x: min(x[0],h)/x[1], reverse = True)
  t = ls[0]
  ans += h//t
  h %= t
print(ans)






Fixed submission:
n,m=map(int, input().split())
s=[list(map(int, input().split())) for i in range(m)]
x=max(a for a,b in s)
dp=[0]*(n+x)
for i in range(0,n+x):
  if i>0:
    dp[i]=min(dp[i-a]+b for a,b in s)
print(min(dp[n:]))