Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    dp = [0 for _ in range(W+1)]
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(W-nm+1)[::-1]:
            a = nm
            if dp[j+a] < dp[j] + nv:
                dp[j+a] = dp[j] + nv
    print(max(dp))

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    dp = [0 for _ in range(W+1)]
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(W-nm+1)[::-1]:
            a = nm
            if dp[j+a] < dp[j] + nv:
                dp[j+a] = dp[j] + nv
    print(max(dp))

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))

if __name__ == "__main__":
    main()

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(N)]
    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
    for i in range(N):
        for w in range(W+1):
            if X[i][0] <= w:
                dp[i+1][w] = max(dp[i][w-X[i][0]]+X[i][1],dp[i+1][w])
            else:
                dp[i+1][w] = dp[i][w]
    dp = np.array(dp)
    print(dp.max())

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))

if __name__ == "__main__":
    main()

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

def main():
    N,W = map(int,input().split())
    X = [list(map(int,input().split())) for _ in range(N)]
    dp = [[0 for _ in range(W+1)] for _ in range(N+1)]
    for i in range(N):
        for w in range(W+1):
            if X[i][0] <= w:
                dp[i+1][w] = max(dp[i][w-X[i][0]]+X[i][1],dp[i+1][w])
            else:
                dp[i+1][w] = dp[i][w]
    dp = np.array(dp)
    print(dp.max())

if __name__ == "__main__":
    main()

Fixed submission:
import sys
input = sys.stdin.readline

def main():
    N,W = map(int,input().split())
    dp = [-1 for _ in range(W+1)]
    dp[W] = 0
    for _ in range(N):
        nm,nv = [int(a) for a in input().split()]
        for j in range(nm,W+1):
            a = nm
            if dp[j] == -1:
                continue
            if dp[j-a] < dp[j] + nv:
                dp[j-a] = dp[j] + nv
    print(max(dp))

if __name__ == "__main__":
    main()