Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
N, W = map(int, input().split())

def solve(N, W): 
    dp = [0]*(W+1)
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp_next = [0] * (W+1)
        for w in range(1, W+1):
            if w >= wi:
                dp_next[w] = max(dp[w - wi] + vi, dp[w])
            else:
                dp_next[w] = dp[w]
        dp = dp_next
    return dp[-1]

print(solve(N, W))

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

N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype='int64')

def solve(N, W):
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp[i][:wi] = dp[i-1][:wi]
        dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)
    return dp[N-1][W]

print(solve(N, W))

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

N, W = map(int, input().split())
dp = [0]*(W+1)

def solve(N, W): 
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp_next = [0] * (W+1)
        for w in range(1, W+1):
            if w >= wi:
                dp_next[w] = max(dp[w - wi] + vi, dp[w])
            else:
                dp_next[w] = dp[w]
        dp = dp_next
    return dp[-1]

print(solve(N, W))


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

N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype='int64')

def solve(N, W):
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp[i][:wi] = dp[i-1][:wi]
        dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)
    return dp[N-1][W]

print(solve(N, W))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [0]*(W+1)

for i in range(0, N):
    wi, vi = map(int, input().split())
    dp_next = [0] * (W+1)
    for w in range(1, W+1):
        if w >= wi:
            dp_next[w] = max(dp[w - wi] + vi, dp[w])
        else:
            dp_next[w] = dp[w]
    dp = dp_next
print(dp[-1])

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

N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype='int64')

def solve(N, W):
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp[i][:wi] = dp[i-1][:wi]
        dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)
    return dp[N-1][W]

print(solve(N, W))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [[0]*(W+1) for _ in range(N)]

for i in range(0, N):
    wi, vi = map(int, input().split())
    for w in range(1, W+1):
        if w >= wi:
            dp[i][w] = max(dp[i-1][w - wi] + vi, dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]
print(dp[N-1][W])

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

N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype='int64')

def solve(N, W):
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp[i][:wi] = dp[i-1][:wi]
        dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)
    return dp[N-1][W]

print(solve(N, W))

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
Weighs = []
Values = []
for _ in range(N):
    w, v = map(int, input().split())
    Weighs.append(w)
    Values.append(v)

dp = [[0]*(W+1) for _ in range(N)]

for i in range(0, N):
    for w in range(1, W+1):
        if w >= Weighs[i]:
            dp[i][w] = max(dp[i-1][w - Weighs[i]] + Values[i], dp[i-1][w])
        else:
            dp[i][w] = dp[i-1][w]
print(dp[N-1][W])

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

N, W = map(int, input().split())
dp = np.zeros((N, W+1), dtype='int64')

def solve(N, W):
    for i in range(0, N):
        wi, vi = map(int, input().split())
        dp[i][:wi] = dp[i-1][:wi]
        dp[i][wi:] = np.fmax(dp[i-1][wi:],
                            dp[i-1][:W+1-wi] + vi)
    return dp[N-1][W]

print(solve(N, W))