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

w = []
v = []

for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

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

for i in range(N):
    for j in range(0, W+1):
        if j - w[i] >= 0:  # i 番目の品物が容量 j に対して（他を0個以上捨てれば）入れられる場合
            if dp[i+1][j] < dp[i][j - w[i]] + v[i]:
                dp[i+1][j] = dp[i][j - w[i]] + v[i]

        if dp[i+1][j] < dp[i][j]:
            dp[i+1][j] = dp[i][j] # i 番目の品物を入れた場合と入れなかった場合の比較

print(dp[N][W])


Fixed submission:
def dp():
    n, W = map(int, input().split())
    wv = (map(int, input().split()) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in wv:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(dp())

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

wv = (map(int, input().split()) for _ in range(N))

dp = [0] * (W+1)

for w, v in wv:
    for j in range(W, w-1, -1):
        DP = dp[j-w] + v
        dp[j] = max(dp[j], DP)

print(max(dp))


Fixed submission:
def dp():
    n, W = map(int, input().split())
    wv = (map(int, input().split()) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in wv:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(dp())

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

wv = list(map(int, input().split()) for _ in range(N))

dp = [0] * (W+1)

for w, v in wv:
    for j in range(W, w-1, -1):
        DP = dp[j-w] + v
        dp[j] = max(dp[j], DP)

print(max(dp))


Fixed submission:
def dp():
    n, W = map(int, input().split())
    wv = (map(int, input().split()) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in wv:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(dp())

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

w = []
v = []

dp = [0] * (W+1)

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

print(max(dp))


Fixed submission:
def dp():
    n, W = map(int, input().split())
    wv = (map(int, input().split()) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in wv:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(dp())

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

w = []
v = []

for i in range(N):
    a, b = map(int, input().split())
    w.append(a)
    v.append(b)

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

for i in range(N):
    for j in range(0, W+1):
        if j - w[i] >= 0:  # i 番目の品物が容量 j に対して（他を0個以上捨てれば）入れられる場合
            dp[i+1][j] = max(dp[i+1][j], dp[i][j - w[i]] + v[i])

        dp[i+1][j] = max(dp[i+1][j], dp[i][j]) # i 番目の品物を入れた場合と入れなかった場合の比較

print(dp[N][W])


Fixed submission:
def dp():
    n, W = map(int, input().split())
    wv = (map(int, input().split()) for _ in range(n))
    dp = [0] * (W+1)

    for w, v in wv:
        for j in range(W, w-1, -1):
            DP = dp[j-w] + v
            if dp[j] < DP:
                dp[j] = DP
    return max(dp)
print(dp())