Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
for i in range(W+1):
  if i>=Wlist[0]:
    dp[0][i]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W+1):
    if j-wi>=0:
      dp[i][j]=max(dp[i-1][j-wi]+Vlist[i],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Fixed submission:
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
for i in range(W+1):
  if i>=Wlist[0]:
    dp[0][i]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W+1):
    if j-wi>=0:
      dp[i][j]=max(dp[i-1][j-wi]+Vlist[i],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
dp[0][Wlist[0]]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W):
    if j+wi<=W:
      dp[i][j+wi]=max(dp[i-1][j]+Vlist[i],dp[i][j+wi])
    dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Fixed submission:
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
for i in range(W+1):
  if i>=Wlist[0]:
    dp[0][i]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W+1):
    if j-wi>=0:
      dp[i][j]=max(dp[i-1][j-wi]+Vlist[i],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Buggy python submission (verdict: Time Limit Exceeded):
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W)] for i in range(N)]
for i in range(N):
  wi=Wlist[i]
  if i==0:
    dp[0][Wlist[0]-1]=Vlist[0]
  else:
    for j in range(W):
      if j+wi<W:
        if j==0:
          dp[i][wi-1]=max(Vlist[i],dp[i][wi-1])
        if dp[i-1][j]!=0:
          dp[i][j+wi]=max(dp[i-1][j]+Vlist[i],dp[i][j+wi])
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Fixed submission:
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
for i in range(W+1):
  if i>=Wlist[0]:
    dp[0][i]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W+1):
    if j-wi>=0:
      dp[i][j]=max(dp[i-1][j-wi]+Vlist[i],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Buggy python submission (verdict: Runtime Error):
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W)] for i in range(N)]
for i in range(N):
  wi=Wlist[i]
  if i==0:
    dp[0][Wlist[0]-1]=Vlist[0]
  else:
    for j in range(W):
      if j+wi<W:
        if j==0:
          dp[i][wi-1]=max(Vlist[i],dp[i][wi-1])
        if dp[i-1][j]!=0:
          dp[i][j+wi]=max(dp[i-1][j]+Vlist[i],dp[i][j+wi])
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1])

Fixed submission:
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
for i in range(W+1):
  if i>=Wlist[0]:
    dp[0][i]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W+1):
    if j-wi>=0:
      dp[i][j]=max(dp[i-1][j-wi]+Vlist[i],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))

Buggy python submission (verdict: Runtime Error):
N,W=int(input())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(N)] for i in range(W)]
for i in range(N):
  wi=Wlist[i]
  for j in range(W):
    if j+wi<W:
    dp[i][j+wi]=max(dp[i-1][j]+Vlist[i],dp[i][j+wi])
    else:
      break
print(max(dp[N-1]))

Fixed submission:
N,W=map(int,input().split())
Wlist=[]
Vlist=[]
for i in range(N):
  w,v=map(int,input().split())
  Wlist+=[w]
  Vlist+=[v]
dp=[[0 for p in range(W+1)] for i in range(N)]
for i in range(W+1):
  if i>=Wlist[0]:
    dp[0][i]=Vlist[0]
for i in range(1,N):
  wi=Wlist[i]
  for j in range(W+1):
    if j-wi>=0:
      dp[i][j]=max(dp[i-1][j-wi]+Vlist[i],dp[i-1][j])
    else:
      dp[i][j]=max(dp[i-1][j],dp[i][j])
print(max(dp[N-1]))