Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
def knapsack(n,c):
  if dp[n][c]!=-1:
    return dp[n][c]
  
  if n < 0 :
    return 0
  if w[n] > c:
    dp[n][c] = knapsack(n-1,c)
    return dp[n][c]
  else:
    opt1 = v[n] + knapsack(n-1,c-w[n])
    opt2 = knapsack(n-1,c)
    dp[n][c] = max(opt1,opt2)
    return dp[n][c]

n,c = map(int,input().split())
w =[];v=[]
size = n+1
dp = np.full((size,c+1),int(-1))
#print(dp)
for _ in range(n):
  wi , vi= map(int,input().split())
  w.append(wi)
  v.append(vi)

result = knapsack(n-1,c)
print(int(result))       
        
        

Fixed submission:
n,W = map(int,input().split())
wt =[];val=[]

dp = [[0 for i in range(W+1)] for j in range(n)]
for _ in range(n):
  wi , vi= map(int,input().split())
  wt.append(wi)
  val.append(vi)

for i in range(W+1):
  if i>=wt[0]:
    dp[0][i]=val[0]   
  else:
    dp[0][i]=0
    
    
    
#print(dp)  
for i in range(1,n):
  wi = wt[i]
  vi = val[i]
  for w in range(1,W+1):
    if wi <= w:
      dp[i][w] = max(vi + dp[i-1][w-wi] , dp[i-1][w] )
    else:
      dp[i][w] = dp[i-1][w]

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

Buggy python submission (verdict: Time Limit Exceeded):

def knapsack(n,c,w,v,dp):
  if dp[n][c]!=None:
    return dp[n][c]
  
  if n == 0 or c == 0:
    dp[n][c]=0
    return dp[n][c]
  if w[n] > c:
    dp[n][c] = knapsack(n-1,c,w,v,dp)
    return dp[n][c]
  else:
    opt1 = v[n] + knapsack(n-1,c-w[n],w,v,dp)
    opt2 = knapsack(n-1,c,w,v,dp)
    dp[n][c] = max(opt1,opt2)
    return dp[n][c]

n,c = map(int,input().split())

w = [-1]; v = [-1]
size = n+1
dp = [ [None for i in range(c+1)] for j in range(n+1)]
for _ in range(n):
  wi , vi= map(int,input().split())
  w.append(wi)
  v.append(vi)

result = knapsack(n,c,w,v,dp)
print(result)        
        
        

Fixed submission:
n,W = map(int,input().split())
wt =[];val=[]

dp = [[0 for i in range(W+1)] for j in range(n)]
for _ in range(n):
  wi , vi= map(int,input().split())
  wt.append(wi)
  val.append(vi)

for i in range(W+1):
  if i>=wt[0]:
    dp[0][i]=val[0]   
  else:
    dp[0][i]=0
    
    
    
#print(dp)  
for i in range(1,n):
  wi = wt[i]
  vi = val[i]
  for w in range(1,W+1):
    if wi <= w:
      dp[i][w] = max(vi + dp[i-1][w-wi] , dp[i-1][w] )
    else:
      dp[i][w] = dp[i-1][w]

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

Buggy python submission (verdict: Time Limit Exceeded):

def knapsack(n,c,w,v,dp):
  if dp[n][c]!=None:
    return dp[n][c]
  
  if n == 0 or c == 0:
    return 0
  if w[n] > c:
    dp[n][c] = knapsack(n-1,c,w,v,dp)
    return dp[n][c]
  else:
    opt1 = v[n] + knapsack(n-1,c-w[n],w,v,dp)
    opt2 = knapsack(n-1,c,w,v,dp)
    dp[n][c] = max(opt1,opt2)
    return dp[n][c]

n,c = map(int,input().split())

w = [-1]; v = [-1]
size = n+1
dp = [ [None for i in range(c+1)] for j in range(n+1)]
for _ in range(n):
  wi , vi= map(int,input().split())
  w.append(wi)
  v.append(vi)

result = knapsack(n,c,w,v,dp)
print(result)        
        
        

Fixed submission:
n,W = map(int,input().split())
wt =[];val=[]

dp = [[0 for i in range(W+1)] for j in range(n)]
for _ in range(n):
  wi , vi= map(int,input().split())
  wt.append(wi)
  val.append(vi)

for i in range(W+1):
  if i>=wt[0]:
    dp[0][i]=val[0]   
  else:
    dp[0][i]=0
    
    
    
#print(dp)  
for i in range(1,n):
  wi = wt[i]
  vi = val[i]
  for w in range(1,W+1):
    if wi <= w:
      dp[i][w] = max(vi + dp[i-1][w-wi] , dp[i-1][w] )
    else:
      dp[i][w] = dp[i-1][w]

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

Buggy python submission (verdict: Time Limit Exceeded):

def knapsack(n,c,w,v,dp):
  if dp[n][c]!=None:
    return dp[n][c]
  
  if n == 0 or c == 0:
    return 0
  if w[n] > c:
    dp[n][c] = knapsack(n-1,c,w,v,dp)
    return dp[n][c]
  else:
    opt1 = v[n] + knapsack(n-1,c-w[n],w,v,dp)
    opt2 = knapsack(n-1,c,w,v,dp)
    dp[n][c] = max(opt1,opt2)
    return dp[n][c]

n,c = map(int,input().split())

w = [-1]; v = [-1]
size = n+1
dp = [ [None for i in range(c+1)] for j in range(n+1)]
for _ in range(n):
  wi , vi= map(int,input().split())
  w.append(wi)
  v.append(vi)

result = knapsack(n,c,w,v,dp)
print(result)        
        
        

Fixed submission:
n,W = map(int,input().split())
wt =[];val=[]

dp = [[0 for i in range(W+1)] for j in range(n)]
for _ in range(n):
  wi , vi= map(int,input().split())
  wt.append(wi)
  val.append(vi)

for i in range(W+1):
  if i>=wt[0]:
    dp[0][i]=val[0]   
  else:
    dp[0][i]=0
    
    
    
#print(dp)  
for i in range(1,n):
  wi = wt[i]
  vi = val[i]
  for w in range(1,W+1):
    if wi <= w:
      dp[i][w] = max(vi + dp[i-1][w-wi] , dp[i-1][w] )
    else:
      dp[i][w] = dp[i-1][w]

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