Buggy python submission (verdict: Time Limit Exceeded):

N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
    
maxValue = sum(value)
dp = [[float("inf") for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    for v in range(1,maxValue+1):
        dp[i][v] = dp[i-1][v]
        if value[i] <= v:
            dp[i][v] = min(dp[i][v],weight[i] + dp[i-1][v-value[i]])
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Fixed submission:
N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
    
maxValue = sum(value)
INF = 10**10
dp = [[INF for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    for v in range(1,maxValue+1):
        if value[i] <= v:
            dp[i][v] = min(dp[i-1][v],weight[i] + dp[i-1][v-value[i]])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
maxValue = N*1000
dp = [[float("inf") for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(1,N+1):
    for v in range(1,maxValue+1):
        dp[i][v] = dp[i-1][v]
        if value[i] > v: continue;
        dp[i][v] = min(dp[i][v],weight[i] + dp[i-1][v-value[i]])
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Fixed submission:
N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
    
maxValue = sum(value)
INF = 10**10
dp = [[INF for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    for v in range(1,maxValue+1):
        if value[i] <= v:
            dp[i][v] = min(dp[i-1][v],weight[i] + dp[i-1][v-value[i]])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Buggy python submission (verdict: Runtime Error):
N,W = map(int,input().split())
weight = []
value = []
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
maxValue = N*1000
dp = [[float("inf") for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0

for i in range(1,N+1):
    for v in range(1,maxValue+1):
        dp[i][v] = dp[i-1][v]
        if value[i] > v: continue;
        dp[i][v] = min(dp[i][v],weight[i] + dp[i-1][v-value[i]])
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)

Fixed submission:
N,W = map(int,input().split())
weight = [0]
value = [0]
for i in range(N):
    w,v = map(int,input().split())
    weight.append(w)
    value.append(v)
    
maxValue = sum(value)
INF = 10**10
dp = [[INF for i in range(maxValue+1)] for j in range(N+1)]
for i in range(N+1):
    dp[i][0] = 0
for i in range(1,N+1):
    for v in range(1,maxValue+1):
        if value[i] <= v:
            dp[i][v] = min(dp[i-1][v],weight[i] + dp[i-1][v-value[i]])
        else:
            dp[i][v] = dp[i-1][v]
ans = 0
for x in range(maxValue+1):
    if dp[N][x] <= W:
        ans = x
print(ans)