Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.buffer.readline
from copy import deepcopy
from collections import deque
def main():
    h, n = map(int, input().split())
    a = deque()
    b = deque()
    aa = a.append
    ba = b.append
    for _ in range(n):
        numa, numb = map(int, input().split())
        aa(numa)
        ba(numb)
    dp = [10**9] * (h + 1)
    dp[0] = 0
    while a:
        dp_c = deepcopy(dp)
        at = a.popleft()
        bt = b.popleft()
        for i1 in range(h + 1):
            if i1 <= at:
                dp[i1] = min(bt, dp_c[i1])
            else:
                dp[i1] = min(dp[i1], dp[i1 - at] + bt)
    print(dp[h])

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h, n = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]

    large_num = 10**9
    dp = [large_num] * (h + 10**4 + 1)
    dp[0] = 0
    for abe in ab:
        a = abe[0]
        b = abe[1]
        for i1 in range(h + 1):
            if dp[i1 + a] > dp[i1] + b:
                dp[i1 + a] = dp[i1] + b
    r = min(dp[h:])

    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
from copy import deepcopy
from collections import deque
def main():
    h, n = map(int, input().split())
    a = deque()
    b = deque()
    aa = a.append
    ba = b.append
    for _ in range(n):
        numa, numb = map(int, input().split())
        aa(numa)
        ba(numb)
    dp = [10**9] * (h + 1)
    dp[0] = 0
    while a:
        dp_c = deepcopy(dp)
        at = a.popleft()
        bt = b.popleft()
        for i1 in range(h + 1):
            if i1 <= at:
                dp[i1] = min(bt, dp_c[i1])
            else:
                dp[i1] = min(dp_c[i1], dp[i1 - at] + bt)
    print(dp[h])

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h, n = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]

    large_num = 10**9
    dp = [large_num] * (h + 10**4 + 1)
    dp[0] = 0
    for abe in ab:
        a = abe[0]
        b = abe[1]
        for i1 in range(h + 1):
            if dp[i1 + a] > dp[i1] + b:
                dp[i1 + a] = dp[i1] + b
    r = min(dp[h:])

    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
def main():
    h, n = map(int, input().split())
    
    inf = float('inf')
    dp = [inf] * (h + 1)
    dp[0] = 0
    for _ in range(n):
        a, b = map(int, input().split())
        dp_c = deepcopy(dp)
        for i1 in range(h + 1):
            if i1 <= a:
                dp[i1] = min(b, dp_c[i1])
            else:
                dp[i1] = min(dp_c[i1], dp[i1 - a] + b)
    print(dp[h])

if __name__ == '__main__':
    main()


Fixed submission:
def main():
    h, n = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]

    large_num = 10**9
    dp = [large_num] * (h + 10**4 + 1)
    dp[0] = 0
    for abe in ab:
        a = abe[0]
        b = abe[1]
        for i1 in range(h + 1):
            if dp[i1 + a] > dp[i1] + b:
                dp[i1 + a] = dp[i1] + b
    r = min(dp[h:])

    print(r)

if __name__ == '__main__':
    main()

Buggy python submission (verdict: Time Limit Exceeded):
from copy import deepcopy
def main():
    h, n = map(int, input().split())
    magics = [tuple(map(int, input().split())) for _ in range(n)]

    inf = float('inf')
    dp = [inf] * (h + 1)
    dp[0] = 0
    for magic in magics:
        dp_c = deepcopy(dp)
        for i1 in range(h + 1):
            if i1 <= magic[0]:
                dp[i1] = min(magic[1], dp_c[i1])
            else:
                dp[i1] = min(dp_c[i1], dp[i1 - magic[0]] + magic[1])
    print(dp[h])


if __name__ == '__main__':
    main()

Fixed submission:
def main():
    h, n = map(int, input().split())
    ab = [tuple(map(int, input().split())) for _ in range(n)]

    large_num = 10**9
    dp = [large_num] * (h + 10**4 + 1)
    dp[0] = 0
    for abe in ab:
        a = abe[0]
        b = abe[1]
        for i1 in range(h + 1):
            if dp[i1 + a] > dp[i1] + b:
                dp[i1 + a] = dp[i1] + b
    r = min(dp[h:])

    print(r)

if __name__ == '__main__':
    main()