Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()

Fixed submission:
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v
V = sum(vs)+1
  

dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for j in range(i, -1, -1):
    for k in range(V):
      if k-v>=0:
        dp[j+1][k] = min(dp[j][k-v]+w, dp[j+1][k])
      dp[j+1][k] = min(dp[j][k], dp[j+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()

Fixed submission:
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v
V = sum(vs)+1
  

dp = [[float('inf')]*(V) for _ in range(N+1)]
# dp[i][j]: i個の品物を使ってjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for j in range(i, -1, -1):
    for k in range(temp+1):
      dp[j+1][k+v] = min(dp[j][k]+w, dp[j+1][k+v])
  temp += v

ans = 0
for i in range(N+1):
  for j in range(V):
    if dp[i][j] <= W:
      ans = max(ans, j)
print(ans)

Fixed submission:
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split())
dp = [[float('inf')]*(10**5+1) for _ in range(N+1)]
# dp[i][j]: i個の品物を使ってjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w, v = map(int, input().split())
  for j in range(i, -1, -1):
    for k in range(temp+1):
      dp[j+1][k+v] = min(dp[j][k]+w, dp[j+1][k+v])
  temp += v

ans = 0
for i in range(N+1):
  for j in range(10**5+1):
    if dp[i][j] <= W:
      ans = max(ans, j)
print(ans)

Fixed submission:
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()

Buggy python submission (verdict: Runtime Error):
import numpy as np
 
N, W = map(int, input().split())
 
dp = np.zeros((N+1, W+1), dtype='uint64')
 
for i in range(N):
  w, v = map(int, input().split()) 
  dp[i+1][:w] = dp[i][:w]
  dp[i+1][w:] = np.maximum(dp[i][w:], dp[i][:-w]+v)
print(np.max(dp[N]))

Fixed submission:
N, W = map(int, input().split())
ws = [0]*N
vs = [0]*N

for i in range(N):
  w, v = map(int, input().split())
  ws[i] = w
  vs[i] = v

V = N*(10**3)+1
dp = [[float('inf')]*V for _ in range(N+1)]
# dp[i][j]: i個の品物までを見てjの価値を実現する最小のw
dp[0][0] = 0
temp = 0

for i in range(N):
  w = ws[i]
  v = vs[i]
  for k in range(V):
    if k-v>=0:
      dp[i+1][k] = min(dp[i][k-v]+w, dp[i+1][k])
    dp[i+1][k] = min(dp[i][k], dp[i+1][k])

for j in range(V-1, -1, -1):
  if dp[N][j] <= W:
    print(j)
    exit()