Buggy python submission (verdict: Time Limit Exceeded):
def main():
  h, n = map(int, input().split())
  l = []
  for i in range(n):
    a, b = map(int, input().split())
    l.append([a, b])

  dp = [10 ** 9 for i in range(h+1)]

  for i in range(h+1):
    for j in range(n):
      if l[j][0] >= i:
        if dp[i] > l[j][1]:
          dp[i] = l[j][1]
      else:
        if dp[i] > l[j][1] + dp[i-l[j][0]]:
          dp[i] = l[j][1] + dp[i-l[j][0]]


  print(dp[h])

main()


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
from sys import stdin
readline = stdin.readline
H, N = map(int, readline().split())
AB = [list(map(int, readline().split())) for _ in range(N)]

dp = [100000000] * (H + 10 ** 4 + 1)
dp[0] = 0
for i in range(H):
    if dp[i] == 100000000:
        continue
    for a, b in AB:
        t = dp[i] + b
        if t < dp[i + a]:
            dp[i + a] = t
print(min(dp[H:]))




Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

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

dp = [10 ** 8 + 1 for i in range(h + 10 ** 4 + 1)]
dp[0] = 0

for i in range(h):
  if dp[i] == 10 ** 8 + 1:
      continue
  for a, b in l:
    x = dp[i] + b
    if dp[i + a] > x:
      dp[i + a] = x

print(min(dp[h:]))


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

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

dp = [10 ** 8 + 1 for i in range(h + 10 ** 4 + 1)]
dp[0] = 0

for i in range(h+1):
  if dp[i] == 10 ** 8 + 1:
      continue
  for a, b in l:
    x = dp[i] + b
    if dp[i + a] > x:
      dp[i + a] = x

print(min(dp[h:]))


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

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

dp = [10 ** 8 + 1 for i in range(h + 10**4 + 1)]
dp[0] = 0

for i in range(h+1):
  if dp[i] == 10 ** 8 + 1:
      continue
  for j in range(n):
    x = dp[i] + l[j][1]
    if dp[i + l[j][0]] > x:
      dp[i + l[j][0]] = x

print(min(dp[h:]))


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  from sys import stdin
  readline = stdin.readline
  h, n = map(int, readline().split())
  l = [list(map(int, readline().split())) for i in range(n)]

  dp = [10 ** 9 for i in range(h+1)]

  for i in range(h+1):
    for j in range(n):
      if l[j][0] >= i:
        if dp[i] > l[j][1]:
          dp[i] = l[j][1]
      else:
        if dp[i] > l[j][1] + dp[i-l[j][0]]:
          dp[i] = l[j][1] + dp[i-l[j][0]]

  print(dp[h])


main()


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  h, n = map(int, input().split())
  l = []
  for i in range(n):
    a, b = map(int, input().split())
    l.append([a, b])

  dp = [10 ** 9 for i in range(h+1)]

  for i in range(h+1):
    for j in range(n):
      if l[j][0] >= i:
        if dp[i] > l[j][1]:
          dp[i] = l[j][1]
      else:
        if dp[i] > l[j][1] + dp[i-l[j][0]]:
          dp[i] = l[j][1] + dp[i-l[j][0]]

  print(dp[h])


main()


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
h, n = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

dp = [10 ** 9 for i in range(h+1)]

for i in range(h+1):
  for j in range(n):
    if l[j][0] >= i:
      if dp[i] > l[j][1]:
        dp[i] = l[j][1]
    else:
      if dp[i] > l[j][1] + dp[i-l[j][0]]:
        dp[i] = l[j][1] + dp[i-l[j][0]]


print(dp[h])


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

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


dp = [10 ** 8 + 1 for i in range(h + 10**4 + 1)]
dp[0] = 0

for i in range(h+1):
  for j in range(n):
    if dp[i] == 10 ** 8 + 1:
      continue

    x = dp[i] + l[j][1]
    if dp[i + l[j][0]] > x:
      dp[i + l[j][0]] = x

print(min(dp[h:]))


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

dp = [10 ** 8 + 1 for i in range(h + 10**4 + 1)]
dp[0] = 0

for i in range(h+1):
  for j in range(n):
    if dp[i] == 10 ** 8 + 1:
      continue

    x = dp[i] + l[j][1]
    if dp[i + l[j][0]] > x:
      dp[i + l[j][0]] = x

print(min(dp[h:]))


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

dp = [10 ** 8 + 1 for i in range(h+1)]
dp[0] = 0

for i in range(h+1):
  for j in range(n):
    y = max(i-l[j][0], 0)
    if dp[i] > l[j][1] + dp[y]:
      dp[i] = l[j][1] + dp[y]


print(dp[h])


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

dp = [10 ** 9 for i in range(h+1)]
dp[0] = 0

for i in range(h+1):
  for j in range(n):
    y = max(i-l[j][0], 0)
    if dp[i] > l[j][1] + dp[y]:
      dp[i] = l[j][1] + dp[y]


print(dp[h])


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

dp = [10 ** 9 for i in range(h+1)]
dp[0] = 0

for i in range(h+1):
  for j in range(n):
    if dp[i] > l[j][1] + dp[max(i-l[j][0], 0)]:
      dp[i] = l[j][1] + dp[max(i-l[j][0], 0)]


print(dp[h])


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()

Buggy python submission (verdict: Time Limit Exceeded):
h, n = map(int, input().split())
l = []
for i in range(n):
  a, b = map(int, input().split())
  l.append([a, b])

dp = [10 ** 9 for i in range(h+1)]

for i in range(h+1):
  for j in range(n):
    if l[j][0] >= i:
      if dp[i] > l[j][1]:
        dp[i] = l[j][1]
    else:
      if dp[i] > l[j][1] + dp[i-l[j][0]]:
        dp[i] = l[j][1] + dp[i-l[j][0]]


print(dp[h])


Fixed submission:
def main():
    from sys import stdin
    readline = stdin.readline
    H, N = map(int, readline().split())
    AB = [list(map(int, readline().split())) for _ in range(N)]

    dp = [100000000] * (H + 10 ** 4 + 1)
    dp[0] = 0
    for i in range(H):
        if dp[i] == 100000000:
            continue
        for a, b in AB:
            t = dp[i] + b
            if t < dp[i + a]:
                dp[i + a] = t
    print(min(dp[H:]))


main()