Problem p02787 (python)

Fixed submission:
#import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, n = map(int, input().split())
    # A = []
    # B = []
    # for _ in range(n):
    #     A.append(a)
    #     B.append(b)
        
    m = 2 * 10**4 + 10
    dp = [float("inf")] * (h+1)
    dp[0] = 0
    # for a, b in zip(A, B):
    #     dp[a] = b
    for _ in range(n):
        a, b = map(int, input().split())
        for i in range(h):
            # for a, b in zip(A, B):
            if i + a < m :
                j = min(i+a, h)
                if dp[j] > 0:
                    dp[j] = min(dp[j], dp[i] + b)
                else:
                    dp[j] = dp[i] + b
    k = h
    # print(dp[:20])
    # while (flag):
    #     if dp[k] > 0:
    #         ans = dp[k]
    #         flag = 0
    #     k += 1
    # d = np.array(dp[k:])
    # print(np.min(d[d.nonzero()]))
    print(dp[h])
    
    
main()

Buggy submission (verdict: Runtime Error):
#import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, n = map(int, input().split())
    # A = []
    # B = []
    # for _ in range(n):
    #     A.append(a)
    #     B.append(b)
        
    m = 2 * 10**4 + 10
    dp = [0] * (h+1)
    dp[0] = 0
    # for a, b in zip(A, B):
    #     dp[a] = b
    for i in range(h):
        a, b = map(int, input().split())
        # for a, b in zip(A, B):
        if i + a < m and dp[i] > 0:
            j = min(i+a, h)
            if dp[j] > 0:
                dp[j] = min(dp[j], dp[i] + b)
            else:
                dp[j] = dp[i] + b
    k = h
    # print(dp[:20])
    # while (flag):
    #     if dp[k] > 0:
    #         ans = dp[k]
    #         flag = 0
    #     k += 1
    # d = np.array(dp[k:])
    # print(np.min(d[d.nonzero()]))
    print(dp[h])
    
    
main()

Buggy submission (verdict: Runtime Error):
#import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, n = map(int, input().split())
    A = []
    B = []
    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        
    m = 2 * 10**4 + 10
    dp = [0] * (h+1)
    for a, b in zip(A, B):
        dp[a] = b
        for i in range(h):
            for a, b in zip(A, B):
                if i + a < m and dp[i] > 0:
                    j = min(i+a, h)
                    if dp[j] > 0:
                        dp[j] = min(dp[j], dp[i] + b)
                    else:
                        dp[j] = dp[i] + b
    k = h
    # print(dp[:20])
    # while (flag):
    #     if dp[k] > 0:
    #         ans = dp[k]
    #         flag = 0
    #     k += 1
    # d = np.array(dp[k:])
    # print(np.min(d[d.nonzero()]))
    print(dp[h])
    
    
main()

Buggy submission (verdict: Runtime Error):
#import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, n = map(int, input().split())
    A = []
    B = []
    for _ in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        
        m = 2 * 10**4 + 10
        dp = [10**5] * (h+1)
        for a, b in zip(A, B):
            dp[a] = b
            for i in range(h):
                for a, b in zip(A, B):
                    if i + a < m and dp[i] > 0:
                        j = min(i+a, h)
                        if dp[j] > 0:
                            dp[j] = min(dp[j], dp[i] + b)
                        else:
                            dp[j] = dp[i] + b
    k = h
    # print(dp[:20])
    # while (flag):
    #     if dp[k] > 0:
    #         ans = dp[k]
    #         flag = 0
    #     k += 1
    # d = np.array(dp[k:])
    # print(np.min(d[d.nonzero()]))
    print(dp[h])
    
    
main()

Buggy submission (verdict: Runtime Error):
import numpy as np
import sys
input = sys.stdin.readline


def main():

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

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

    m = 2 * 10**4 + 10
    dp = [0] * m
    for a, b in zip(A, B):
        dp[a] = b
    for i in range(10**4 + 1):
        for a, b in zip(A, B):
            # if i + a < 10**4:
            # print(i + a)
            # print(dp[i], dp[i + a], b, i + a)
            if i + a < m and dp[i] > 0:
                if dp[i + a] > 0:
                    dp[i + a] = min(dp[i + a], dp[i] + b)
                else:
                    dp[i + a] = dp[i] + b
    k = h
    # print(dp[:20])
    # while (flag):
    #     if dp[k] > 0:
    #         ans = dp[k]
    #         flag = 0
    #     k += 1
    d = np.array(dp[k:])
    print(np.min(d[d.nonzero()]))


main()

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


def main():

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

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

    dp = [0] * 10**4
    for a, b in zip(A, B):
        dp[a] = b
    for i in range(10**4):
        for a, b in zip(A, B):
            # if i + a < 10**4:
            # print(i + a)
            # print(dp[i], dp[i + a], b, i + a)
            if i + a < 10**4 and dp[i] > 0:
                if dp[i + a] > 0:
                    dp[i + a] = min(dp[i + a], dp[i] + b)
                else:
                    dp[i + a] = dp[i] + b
    k = h
    flag = 1
    ans = 0
    # print(dp[:20])
    while (flag):
        # print(k)
        if dp[k] > 0:
            ans = dp[k]
            flag = 0
        k += 1
    print(ans)


main()