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

    N, W = map(int, input().split())

    dp = np.zeros(W+1, dtype=np.int64)

    for _ in range(N):
    w, v = map(int, input().split())
    np.maximum(dp[:-w]+v, dp[w:], out=dp[w:])

    print(dp[-1])


##########
if __name__ == "__main__":
    e()


Fixed submission:
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    def solve(N, W, wv):
        dp = [-1] * (W+1)
        dp[0] = 0

        for i in range(N):
            wi = wv[i][0]
            vi = wv[i][1]

            for j in range(W-wi, -1, -1):
                # print('i, wi, j = {}, {}, {}'.format(i, wi, j))
                if dp[j] == -1:
                    continue
                dp[j+wi] = max(dp[j+wi], dp[j] + vi)
                # print(dp)

        return max(dp)

    N, W = map(int, input().split())
    wv = tuple(tuple(map(int, input().split())) for i in range(N))
    print(solve(N, W, wv))


##########
if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

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

    N, W = map(int, input().split())
    wv = np.array([list(map(int, input().split())) for i in range(0, N)])

    # DPテーブル
    dp = np.zeros((N+1, W+1), dtype=int)

    def solve():
        for n in range(N - 1, -1, -1):
            for w in range(0, W + 1):
                if w < wv[n, 0]:
                    dp[n, w] = dp[n + 1, w]
                else:
                    dp[n, w] = max(
                        dp[n+1, w], dp[n+1, w - wv[n, 0]] + wv[n, 1])
        print(dp[0, W])

    solve()


##########
if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

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

N, W = map(int, input().split())
wv = np.array([list(map(int, input().split())) for i in range(0, N)])

# DPテーブル
dp = np.zeros((N+1, W+1), dtype=int)


def solve():
    for n in range(N - 1, -1, -1):
        for w in range(0, W + 1):
            if w < wv[n, 0]:
                dp[n, w] = dp[n + 1, w]
            else:
                dp[n, w] = max(dp[n+1, w], dp[n+1, w - wv[n, 0]] + wv[n, 1])

    print(dp[0, W])


def main():
    solve()


##########
if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, W = map(int, input().split())
    items = []
    for i in range(N):
        w, v = map(int, input().split())
        items.append({'value': v, 'weight': w})

    def knapsack(i, w):
        if i >= N:
            return 0
        elif w - items[i]['weight'] < 0:
            return knapsack(i+1, w)
        else:
            v1 = knapsack(i+1, w)
            v2 = knapsack(i+1, w - items[i]['weight']) + items[i]['value']
            return max(v1, v2)

    print(knapsack(0, W))


##########
if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, W = map(int, input().split())
    V = {}

    for i in range(N):
        w, v = map(int, input().split())

        # 重さ j+w での最大価値
        X = {}
        for j in V.keys():
            if j+w <= W:
                X[j+w] = max(V.get(j+w, 0), V.get(j, 0) + v)

        for k in X.keys():
            V[k] = X[k]

        # 重さ w での最大価値 (単体での最大価値)
        if w <= W:
            V[w] = max(V.get(w, 0), v)

    print(max(V.values()))


##########
if __name__ == "__main__":
    main()


Fixed submission:
def solve(N,W,wv):
    dp=[-1]*(W+1)
    dp[0]=0
    for i in range(N):
        cur_w=wv[i][0]
        cur_v=wv[i][1]
        for j in range(W-cur_w,-1,-1):
            if dp[j]==-1:
                continue
            if dp[j+cur_w]<dp[j]+cur_v:
                dp[j+cur_w]=dp[j]+cur_v
    return max(dp)


N,W=map(int,input().split())
wv=tuple(tuple(map(int,input().split())) for _ in range(N))
print(solve(N,W,wv))