Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

WV = []

N, W = [int(v) for v in input().strip().split(' ')]

for _ in range(N):
    WV.append([int(v) for v in sys.stdin.readline().split(' ')])


dp = np.zeros((N + 1, W + 1), dtype = 'uint64')
for i in range(N):
    for w in range(W + 1):
        if w - WV[i][0] >= 0:
            dp[i + 1][w] = max(dp[i + 1][w], WV[i][1] + dp[i][w - WV[i][0]])
        dp[i + 1][w] = max(dp[i + 1][w], dp[i][w])
print(dp[N][W])



Fixed submission:
import numpy as np
import sys

N, W = [int(v) for v in input().strip().split(' ')]
dp = np.zeros(W + 1, dtype = 'uint64')

for _ in range(N):
    w, v = [int(v) for v in sys.stdin.readline().split(' ')]
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

print(dp[W])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
import numpy as np
sys.setrecursionlimit(10 ** 7)

WV = []

N, W = [int(v) for v in input().strip().split(' ')]

for _ in range(N):
    WV.append([int(v) for v in input().strip().split(' ')])


dp = np.zeros((N + 1, W + 1), dtype = 'uint64')
for i in range(N):
    for w in range(W + 1):
        if w - WV[i][0] >= 0:
            dp[i + 1][w] = max(dp[i + 1][w], WV[i][1] + dp[i][w - WV[i][0]])
        dp[i + 1][w] = max(dp[i + 1][w], dp[i][w])
print(dp[N][W])



Fixed submission:
import numpy as np
import sys

N, W = [int(v) for v in input().strip().split(' ')]
dp = np.zeros(W + 1, dtype = 'uint64')

for _ in range(N):
    w, v = [int(v) for v in sys.stdin.readline().split(' ')]
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

print(dp[W])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

WV = []

N, W = [int(v) for v in input().strip().split(' ')]

for _ in range(N):
    WV.append([int(v) for v in input().strip().split(' ')])

cache = {}
def find(w, l):   # あとw持てるときの最大価値（lはすでにナップサックに入っているもの）
    if (w, l) in cache:
        return cache[(w, l)]
    mx = 0
    for i in range(N):
        if w - WV[i][0] < 0 or l & (1 << i):
            continue
        mx = max(mx, WV[i][1] + find(w - WV[i][0], l + 1 << i))
    cache[(w, l)] = mx
    return mx

print(find(W, 0))


Fixed submission:
import numpy as np
import sys

N, W = [int(v) for v in input().strip().split(' ')]
dp = np.zeros(W + 1, dtype = 'uint64')

for _ in range(N):
    w, v = [int(v) for v in sys.stdin.readline().split(' ')]
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

print(dp[W])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

WV = []

N, W = [int(v) for v in input().strip().split(' ')]

for _ in range(N):
    WV.append([int(v) for v in input().strip().split(' ')])

def memoize(f):
    cache = {}
    def helper(x, y):
        if (x, y) not in cache:
            cache[(x, y)] = f(x, y)
        return cache[(x, y)]
    return helper

@memoize
def find(w, l):   # あとw持てるときの最大価値（lはすでにナップサックに入っているもの）
    mx = 0
    for i in range(N):
        if w - WV[i][0] < 0 or l & (1 << i):
            continue
        mx = max(mx, WV[i][1] + find(w - WV[i][0], l + 1 << i))
    return mx

print(find(W, 0))


Fixed submission:
import numpy as np
import sys

N, W = [int(v) for v in input().strip().split(' ')]
dp = np.zeros(W + 1, dtype = 'uint64')

for _ in range(N):
    w, v = [int(v) for v in sys.stdin.readline().split(' ')]
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

print(dp[W])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

WV = []

N, W = [int(v) for v in input().strip().split(' ')]

for _ in range(N):
    WV.append([int(v) for v in input().strip().split(' ')])

def find(w, l):   # あとw持てるときの最大価値（lはすでにナップサックに入っているもの）
    mx = 0
    for i in range(N):
        if w - WV[i][0] < 0 or l & (1 << i):
            continue
        mx = max(mx, WV[i][1] + find(w - WV[i][0], l + 1 << i))
    return mx

print(find(W, 0))


Fixed submission:
import numpy as np
import sys

N, W = [int(v) for v in input().strip().split(' ')]
dp = np.zeros(W + 1, dtype = 'uint64')

for _ in range(N):
    w, v = [int(v) for v in sys.stdin.readline().split(' ')]
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

print(dp[W])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10 ** 7)

WV = []

N, W = [int(v) for v in input().strip().split(' ')]

for _ in range(N):
    WV.append([int(v) for v in input().strip().split(' ')])

def find(w, l):   # あとw持てるときの最大価値（lはすでにナップサックに入っているもの）
    mx = 0
    for i in range(N):
        if w - WV[i][0] < 0 or i in l:
            continue
        mx = max(mx, WV[i][1] + find(w - WV[i][0], l + [i]))
    return mx

print(find(W, []))


Fixed submission:
import numpy as np
import sys

N, W = [int(v) for v in input().strip().split(' ')]
dp = np.zeros(W + 1, dtype = 'uint64')

for _ in range(N):
    w, v = [int(v) for v in sys.stdin.readline().split(' ')]
    np.maximum(dp[:-w] + v, dp[w:], out = dp[w:])

print(dp[W])