Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

INFTY = -1
MAX_V = 10**5
dp = [[INFTY]*(MAX_V+1) for _ in range(N)]
dp[0][S[0][1]] = S[0][0]

for i in range(1, N):
    w, v = S[i]
    for j in range(v):
        dp[i][j] = dp[i-1][j]

    if dp[i-1][v] == -1:
        dp[i][v] = w
    else:
        dp[i][v] = min(dp[i-1][v], w)

    for j in range(v+1, MAX_V+1):
        if dp[i-1][j] == -1 and dp[i-1][j-v] == -1:
            continue
        elif dp[i-1][j] == -1:
            if dp[i-1][j-v]+w > W:
                continue
            else:
                dp[i][j] = dp[i-1][j-v]+w
        elif dp[i-1][j-v] == -1:
            dp[i][j] = dp[i-1][j]
        else:
            if dp[i-1][j-v]+w > W:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for i in range(MAX_V, 0, -1):
    if dp[N-1][i] != -1:
        print(i)
        break


Fixed submission:
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

INFTY = -1
MAX_V = 10**5
dp = [[INFTY]*(MAX_V+1) for _ in range(N)]
dp[0][S[0][1]] = S[0][0]

for i in range(1, N):
    w, v = S[i]
    for j in range(v):
        dp[i][j] = dp[i-1][j]

    if dp[i-1][v] == -1:
        dp[i][v] = w
    else:
        dp[i][v] = min(dp[i-1][v], w)

    for j in range(v+1, MAX_V+1):
        if dp[i-1][j] == -1 and dp[i-1][j-v] == -1:
            continue
        elif dp[i-1][j] == -1:
            if dp[i-1][j-v]+w > W:
                continue
            else:
                dp[i][j] = dp[i-1][j-v]+w
        elif dp[i-1][j-v] == -1:
            dp[i][j] = dp[i-1][j]
        else:
            if dp[i-1][j-v]+w > W:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for i in range(MAX_V, 0, -1):
    if dp[N-1][i] != -1:
        print(i)
        break

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

INFTY = -1
MAX_V = 10**5
dp = [[INFTY]*(MAX_V+1) for _ in range(N)]
dp[0][S[0][1]] = S[0][0]

for i in range(1, N):
    w, v = S[i]
    for j in range(v):
        dp[i][j] = dp[i-1][j]

    if dp[i-1][v] == -1:
        dp[i][v] = w
    else:
        dp[i][v] = min(dp[i-1][v], w)

    for j in range(v+1, MAX_V+1):
        if dp[i-1][j] == -1 and dp[i-1][j-v] == -1:
            pass
        elif dp[i-1][j] == -1:
            if dp[i-1][j-v]+w > W:
                pass
            else:
                dp[i][j] = dp[i-1][j-v]+w
        elif dp[i-1][j-w] == -1:
            dp[i][j] = dp[i-1][j]
        else:
            if dp[i-1][j-v]+w > W:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for i in range(MAX_V, 0, -1):
    if dp[N-1][i] != -1:
        print(i)
        break

Fixed submission:
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

INFTY = -1
MAX_V = 10**5
dp = [[INFTY]*(MAX_V+1) for _ in range(N)]
dp[0][S[0][1]] = S[0][0]

for i in range(1, N):
    w, v = S[i]
    for j in range(v):
        dp[i][j] = dp[i-1][j]

    if dp[i-1][v] == -1:
        dp[i][v] = w
    else:
        dp[i][v] = min(dp[i-1][v], w)

    for j in range(v+1, MAX_V+1):
        if dp[i-1][j] == -1 and dp[i-1][j-v] == -1:
            continue
        elif dp[i-1][j] == -1:
            if dp[i-1][j-v]+w > W:
                continue
            else:
                dp[i][j] = dp[i-1][j-v]+w
        elif dp[i-1][j-v] == -1:
            dp[i][j] = dp[i-1][j]
        else:
            if dp[i-1][j-v]+w > W:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for i in range(MAX_V, 0, -1):
    if dp[N-1][i] != -1:
        print(i)
        break

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

INFTY = -1*10**7
dp = [[0]*(W+1) for _ in range(N)]
dp[0][S[0][0]] = S[0][1]

for i in range(1, N):
    w, v = S[i]
    for j in range(w):
        dp[i][j] = dp[i-1][j]
    dp[i][w] = max(dp[i-1][w], S[i][1])
    for j in range(w+1, W+1):
        if dp[i-1][j] == 0 and dp[i-1][j-w] == 0:
            pass
        elif dp[i-1][j] == 0:
            dp[i][j] = dp[i-1][j-w]+v
        elif dp[i-1][j-w] == 0:
            dp[i][j] = dp[i-1][j]
        else:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w]+v)

print(max(dp[N-1]))

Fixed submission:
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
S = [list(map(int, input().split())) for _ in range(N)]

INFTY = -1
MAX_V = 10**5
dp = [[INFTY]*(MAX_V+1) for _ in range(N)]
dp[0][S[0][1]] = S[0][0]

for i in range(1, N):
    w, v = S[i]
    for j in range(v):
        dp[i][j] = dp[i-1][j]

    if dp[i-1][v] == -1:
        dp[i][v] = w
    else:
        dp[i][v] = min(dp[i-1][v], w)

    for j in range(v+1, MAX_V+1):
        if dp[i-1][j] == -1 and dp[i-1][j-v] == -1:
            continue
        elif dp[i-1][j] == -1:
            if dp[i-1][j-v]+w > W:
                continue
            else:
                dp[i][j] = dp[i-1][j-v]+w
        elif dp[i-1][j-v] == -1:
            dp[i][j] = dp[i-1][j]
        else:
            if dp[i-1][j-v]+w > W:
                dp[i][j] = dp[i-1][j]
            else:
                dp[i][j] = min(dp[i-1][j], dp[i-1][j-v]+w)

for i in range(MAX_V, 0, -1):
    if dp[N-1][i] != -1:
        print(i)
        break