Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]

dp=[[0]*(W+1) for i in range(n+1)]
for i in range(n-1,-1,-1):
  for j in range(W+1):
    if j<items[i][0]:
      dp[i][j]=dp[i+1][j]
    else:
      dp[i][j]=max(dp[i+1][j],dp[i+1][j-items[i][0]]+items[i][1])

print(dp[0][W])
    

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

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
import numpy as np

dp=np.zeros([n+1,W+1],dtype=np.int64)
for i in range(n):
  w=items[i][0]
  v=items[i][1]
  dp[i+1][:w]=dp[i][:w]
  dp[i+1][w:]=np.maximum(dp[i][w:],dp[i][:-w]+v)
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
w=[items[i][0] for i in range(n)]
v=[items[i][1] for i in range(n)]

dp=[[0]*(W+1) for i in range(n+1)]
for i in range(n-1,-1,-1):
  for j in range(W+1):
    if j<w[i]:
      dp[i][j]=dp[i+1][j]
    else:
      dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i])

print(dp[0][W])
    
    

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

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
import numpy as np

dp=np.zeros([n+1,W+1],dtype=np.int64)
for i in range(n):
  w=items[i][0]
  v=items[i][1]
  dp[i+1][:w]=dp[i][:w]
  dp[i+1][w:]=np.maximum(dp[i][w:],dp[i][:-w]+v)
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
w=[items[i][0] for i in range(n)]
v=[items[i][1] for i in range(n)]

memo=[[-1]*(W+1) for i in range(n+1)]
def dfs(i,j):
  global memo
  if memo[i][j]>=0:
    return memo[i][j]
  else :
    if i==n:
      memo[i][j]=0
    elif j<w[i]:
      memo[i][j]=dfs(i+1,j)
    else:
      memo[i][j]=max(dfs(i+1,j),dfs(i+1,j-w[i])+v[i])
  return memo[i][j]

print(dfs(0,W))

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

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
import numpy as np

dp=np.zeros([n+1,W+1],dtype=np.int64)
for i in range(n):
  w=items[i][0]
  v=items[i][1]
  dp[i+1][:w]=dp[i][:w]
  dp[i+1][w:]=np.maximum(dp[i][w:],dp[i][:-w]+v)
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
w=[items[i][0] for i in range(n)]
v=[items[i][1] for i in range(n)]

memo=[[-1]*(W+1) for i in range(n+1)]
def dfs(i,j):
  if memo[i][j]>=0:
    return memo[i][j]
  else :
    if i==n:
      memo[i][j]=0
      return memo[i][j]
    elif j<w[i]:
      memo[i][j]=dfs(i+1,j)
      return memo[i][j]
    else:
      memo[i][j]=max(dfs(i+1,j),dfs(i+1,j-w[i])+v[i])
      return memo[i][j]
print(dfs(0,W))

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

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
import numpy as np

dp=np.zeros([n+1,W+1],dtype=np.int64)
for i in range(n):
  w=items[i][0]
  v=items[i][1]
  dp[i+1][:w]=dp[i][:w]
  dp[i+1][w:]=np.maximum(dp[i][w:],dp[i][:-w]+v)
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
w=[items[i][0] for i in range(n)]
v=[items[i][1] for i in range(n)]

memo=[[-1]*(W+1) for i in range(n+1)]
def dfs(i,j):
  if i==n:
    return 0
  if memo[i][j]!=-1:
    return memo[i][j]
  else:
    if  j<w[i]:
      memo[i][j]=dfs(i+1,j)
      return memo[i][j]
    else:
      memo[i][j]=max(dfs(i+1,j),dfs(i+1,j-w[i])+v[i])
      return memo[i][j]
print(dfs(0,W))

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

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
import numpy as np

dp=np.zeros([n+1,W+1],dtype=np.int64)
for i in range(n):
  w=items[i][0]
  v=items[i][1]
  dp[i+1][:w]=dp[i][:w]
  dp[i+1][w:]=np.maximum(dp[i][w:],dp[i][:-w]+v)
print(dp[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
w=[items[i][0] for i in range(n)]
v=[items[i][1] for i in range(n)]

memo=[[-1]*(W+1) for i in range(n+1)]
def dfs(i,j):
  if i==n:
    return 0
  if memo[i][j]!=-1:
    return memo[i][j]
  else:
    if  j<w[i]:
      return dfs(i+1,j)
    else:
      return max(dfs(i+1,j),dfs(i+1,j-w[i])+v[i])
print(dfs(0,W))

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

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
import numpy as np

dp=np.zeros([n+1,W+1],dtype=np.int64)
for i in range(n):
  w=items[i][0]
  v=items[i][1]
  dp[i+1][:w]=dp[i][:w]
  dp[i+1][w:]=np.maximum(dp[i][w:],dp[i][:-w]+v)
print(dp[-1][-1])

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

def napsack(n,weight,weights,values):
  dp=[[0]*(n+1) for i in range(weight+1)]
  for i in range(1,n+1):
    for j in range(weight+1):
      if j-weights[i-1]>=0:
        dp[j][i]=np.maximum(dp[j][i],dp[j-weights[i-1]][i-1]+values[i-1])
      else:
        dp[j][i]=np.maximum(dp[j][i-1],dp[j][i])

  return  dp[weight][n]
     
n,w=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
W=[items[i][0] for i in range(n)]
V=[items[i][1] for i in range(n)]
print(napsack(n,w,W,V))




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

n,W=map(int,input().split())
items=[list(map(int,input().split())) for i in range(n)]
import numpy as np

dp=np.zeros([n+1,W+1],dtype=np.int64)
for i in range(n):
  w=items[i][0]
  v=items[i][1]
  dp[i+1][:w]=dp[i][:w]
  dp[i+1][w:]=np.maximum(dp[i][w:],dp[i][:-w]+v)
print(dp[-1][-1])