Buggy python submission (verdict: Time Limit Exceeded):
from itertools import product

N, W = map(int, input().split())
wv = [[0, 0]] + [[int(_) for _ in input().split()] for _ in range(N)]
dp = [[0]*(2*W) for _ in range(2*N)]

for i, tot in product(range(1, N+1), range(1, W+1)):
    if tot >= wv[i][0]:
        dp[i][tot] = max(dp[i-1][tot], dp[i-1][tot-wv[i][0]]+wv[i][1])
    else:
        dp[i][tot] = dp[i-1][tot]

print(dp[N][W])

Fixed submission:
import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

print(dp[-1][-1])

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


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    dp[i][:w_v[i][0]] = dp[i-1][:w_v[i][0]]
    for w in range(w_v[i][0], W+1):
        dp[i][w] = max(dp[i-1][w], dp[i-1][w - w_v[i][0]] + w_v[i][1])

print(dp[-1][-1])

Fixed submission:
import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

print(dp[-1][-1])

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


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    dp[i][:w_v[i][0]] = dp[i-1][:w_v[i][0]]
    for w in range(w_v[i][0], W+1):
        dp[i][w] = max(dp[i-1][w], dp[i-1][w - w_v[i][0]] + w_v[i][1])

print(dp[-1][-1])

Fixed submission:
import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

print(dp[-1][-1])

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


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    for w in range(W+1):
        dp[i][w] = (dp[i-1][w] if w - w_v[i][0] < 0 else max(dp[i-1][w], dp[i-1][w - w_v[i][0]] + w_v[i][1]))

 
print(dp[N-1][W])

Fixed submission:
import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

print(dp[-1][-1])

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


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

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

Fixed submission:
import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

print(dp[-1][-1])

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

N, W = map(int, input().split())
w_v = [[int(x) for x in input().split()] for _ in range(N)]
dp = [[0] * (W+1) for _ in range(N)]

for i in range(w_v[0][0], W+1):
    dp[0][i] = w_v[0][1]
    
for i in range(1, N):
    for w in range(W+1):
        if w - w_v[i][0] < 0:
            dp[i][w] = dp[i-1][w]
        else:
            dp[i][w] = max(dp[i-1][w], dp[i-1][w - w_v[i][0]] + w_v[i][1])

print(dp[N-1][W])

Fixed submission:
import numpy as np


N, W = map(int, input().split())
w_v = [[int(_) for _ in input().split()] for _ in range(N)]
dp = np.zeros([N, W+1], dtype=int)
dp[0][w_v[0][0]:] = w_v[0][1]

for i in range(1, N):
    key = w_v[i][0]
    dp[i][:key] = dp[i-1][:key]
    dp[i][key:] = np.maximum(dp[i-1][key:], dp[i-1][:-key] + w_v[i][1])

print(dp[-1][-1])