Buggy python submission (verdict: Runtime Error):
import numpy as np

def main():
    H,N = map(int, input().split())
    weight = list(); value = list()
    for n in range(N):
        temp = input().split()
        weight.append(int(temp[0]))
        value.append(int(temp[1]))
    
    inf = float("inf")
    dp = np.zeros([N+1, H+max(weight)+1])
    for i in range(N+1):
        for j in range(H+max(weight)+1):
            dp[i,j] = inf
    for i in range(N+1): dp[i,0] = 0
    for i in range(N):
        for h in range(H+max(weight)+1):
            if(weight[i] <= h):
                dp[i+1,h]=min(dp[i,h-weight[i]]+value[i], dp[i+1,h-weight[i]]+value[i], dp[i,h])
            else:
                dp[i+1,h]=dp[i,h]
    res = int(min(dp[N][H:]))
    print(res)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    H,N = map(int, input().split())
    weight = list(); value = list()
    for n in range(N):
        temp = input().split()
        weight.append(int(temp[0]))
        value.append(int(temp[1]))
    
    inf = float("inf")
    dp = [[inf for i in range(H+max(weight)+1)] for j in range(N+1)]
    for i in range(N+1): dp[i][0] = 0
    for i in range(N):
        for h in range(H+max(weight)+1):
            if(weight[i] <= h):
                dp[i+1][h]=min(dp[i][h-weight[i]]+value[i], dp[i+1][h-weight[i]]+value[i], dp[i][h])
            else:
                dp[i+1][h]=dp[i][h]
    res = int(min(dp[N][H:]))
    print(res)



if __name__ == "__main__":
    main()

Buggy python submission (verdict: Runtime Error):
import numpy as np

def main():
    H,N = map(int, input().split())
    weight = list(); value = list()
    for n in range(N):
        temp = input().split()
        weight.append(int(temp[0]))
        value.append(int(temp[1]))
    
    inf = float("inf")
    dp = np.zeros([N+1, H+max(weight)+1])
    for i in range(N+1):
        for j in range(H+max(weight)+1):
            dp[i,j] = inf
    for i in range(N+1): dp[i,0] = 0
    for i in range(N):
        for h in range(H+max(weight)+1):
            if(weight[i] <= h):
                dp[i+1,h]=min(dp[i,h-weight[i]]+value[i], dp[i+1,h-weight[i]]+value[i], dp[i,h])
            else:
                dp[i+1,h]=dp[i,h]
    res = int(min(dp[N][H:]))
    print(res)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    H,N = map(int, input().split())
    weight = list(); value = list()
    for n in range(N):
        temp = input().split()
        weight.append(int(temp[0]))
        value.append(int(temp[1]))
    
    inf = float("inf")
    dp = [[inf for i in range(H+max(weight)+1)] for j in range(N+1)]
    for i in range(N+1): dp[i][0] = 0
    for i in range(N):
        for h in range(H+max(weight)+1):
            if(weight[i] <= h):
                dp[i+1][h]=min(dp[i][h-weight[i]]+value[i], dp[i+1][h-weight[i]]+value[i], dp[i][h])
            else:
                dp[i+1][h]=dp[i][h]
    res = int(min(dp[N][H:]))
    print(res)



if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np

def main():
    H,N = map(int, input().split())
    weight = list(); value = list()
    for n in range(N):
        temp = input().split()
        weight.append(int(temp[0]))
        value.append(int(temp[1]))
    
    inf = float("inf")
    dp = np.zeros([N+1, H+max(weight)+1])
    for i in range(N+1):
        for j in range(H+max(weight)+1):
            dp[i,j] = inf
    for i in range(N+1): dp[i,0] = 0
    for i in range(N):
        for h in range(H+max(weight)+1):
            if(weight[i] <= h):
                dp[i+1,h]=min(dp[i,h-weight[i]]+value[i], dp[i+1,h-weight[i]]+value[i], dp[i,h])
            else:
                dp[i+1,h]=dp[i,h]
    res = int(min(dp[N][H:]))
    print(res)

if __name__ == "__main__":
    main()


Fixed submission:
def main():
    H,N = map(int, input().split())
    weight = list(); value = list()
    for n in range(N):
        temp = input().split()
        weight.append(int(temp[0]))
        value.append(int(temp[1]))
    
    inf = float("inf")
    dp = [[inf for i in range(H+max(weight)+1)] for j in range(N+1)]
    for i in range(N+1): dp[i][0] = 0
    for i in range(N):
        for h in range(H+max(weight)+1):
            if(weight[i] <= h):
                dp[i+1][h]=min(dp[i][h-weight[i]]+value[i], dp[i+1][h-weight[i]]+value[i], dp[i][h])
            else:
                dp[i+1][h]=dp[i][h]
    res = int(min(dp[N][H:]))
    print(res)



if __name__ == "__main__":
    main()