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

N,W = map(int,input().split())
"""
DP = np.zeros(W+1,dtype=int)
for _ in range(N):
  w,v = map(int,input().split())
  np.maximum(DP[:-w]+v,DP[w:],out=DP[w:])
print(DP.max())
"""
DP= np.full(N*10000000+1,W+1)
DP[0] = 0
for _ in range(N):
  w,v = map(int,input().split())
  np.minimum(DP[:-v]+w,DP[v:],out = DP[v:])
print(np.max(np.where(DP<=W)))

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  ws = []
  ps = []
  for _ in range(N):
    w, v = map(int, input().split())
    ws.append(w)
    ps.append(v)
  for i in range(len(ws)):  
    for j in range(W - ws[i], -1, -1):
      dpi = dp[j]
      if dpi != -1:
        if dp[j + ws[i]] < dpi + ps[i]:
          dp[j + ws[i]] = dpi + ps[i]
  print(max(dp))
main()

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [-1] * (W + 1)
dp[0] = 0
ws = []
ps = []
for _ in range(N):
  w, v = map(int, input().split())
  ws.append(w)
  ps.append(v)
  
for i in range(len(ws)):  
  for j in range(W - ws[i], -1, -1):
    dpi = dp[j]
    if dpi != -1:
      if dp[j + ws[i]] < dpi + ps[i]:
        dp[j + ws[i]] = dpi + ps[i]
print(max(dp))

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()

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

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
weight = []
value = []

for _ in range(N):
  w,v = map(int,input().split())
  weight.append(w)
  value.append(v)

DP = [[0]*(W+1) for _ in range(N+1)]
ret = 0
for i in range(len(weight)):
  for j in range(W+1):
    if j < weight[i]:
      DP[i+1][j] = DP[i][j]
    if j + weight[i] <= W:
      DP[i+1][j+weight[i]] = max(DP[i+1][j+weight[i]],DP[i][j]+value[i])
      ret = max(DP[i+1][j+weight[i]],ret)
print(ret)

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
weight = []
value = []

for _ in range(N):
  w,v = map(int,input().split())
  weight.append(w)
  value.append(v)

DP = [[0]*(W+1) for _ in range(N+1)]  

def knapsack(n,w):
  if w >W:
    return -100000000000000000000
  if n >= len(weight):
    return 0
  if DP[n][w] >0:
      return DP[n][w]
  DP[n][w] = max(knapsack(n+1,w),knapsack(n+1,w+weight[n])+value[n])
  return DP[n][w]
print(knapsack(0,0))

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
weight = []
value = []

for _ in range(N):
  w,v = map(int,input().split())
  weight.append(w)
  value.append(v)

def knapsack(n,w):
  if w >W:
    return -1000
  if n >= len(weight):
    return 0
  return max(knapsack(n+1,w),knapsack(n+1,w+weight[n])+value[n])
print(knapsack(0,0))

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()

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

Fixed submission:
def dynamicprogramming():
  N, W = map(int, input().split())
  dp = [-1] * (W + 1)
  dp[0] = 0
  for _ in range(N):
    w, v = map(int, input().split())
    for i in range(W - w, -1, -1):
        dpi = dp[i]
        if dpi != -1:
          if dp[i + w] < dpi + v:
            dp[i + w] = dpi + v
  print(max(dp))

dynamicprogramming()