Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, W =  list(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):
            pre_v = dp[i]
            if pre_v == -1: continue
            dp[i + w] = max(dp[i + w], pre_v + v)

    print(max(dp))

main()


Fixed submission:
def main():
    N, W =  list(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):
            if dp[i] != -1 and dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()

Buggy python submission (verdict: Time Limit Exceeded):
def main():
    N, W =  list(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):
            if dp[i] == -1: continue
            dp[i + w] = max(dp[i + w], dp[i] + v)

    print(max(dp))

main()


Fixed submission:
def main():
    N, W =  list(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):
            if dp[i] != -1 and dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()

Buggy python submission (verdict: Time Limit Exceeded):
N, W =  list(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):
        if dp[i] == -1: continue
        dp[i + w] = max(dp[i + w], dp[i] + v)

print(max(dp))


Fixed submission:
def main():
    N, W =  list(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):
            if dp[i] != -1 and dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()

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

dp = [0] * (W + 1)

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

print(max(dp))


Fixed submission:
def main():
    N, W =  list(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):
            if dp[i] != -1 and dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()

Buggy python submission (verdict: Time Limit Exceeded):
N, W =  list(map(int, input().split()))
w_list = []
v_list = []
dp = []
for _ in range(N):
    w, v = list(map(int, input().split()))
    w_list.append(w)
    v_list.append(v)
    dp.append({})

dp.append({})

for i in range(N + 1):
    for w in range(0, W + 1):
        dp[i][w] = 0


for i in range(N):
    for j in range(W + 1):
        sum_w = j
        if sum_w - w_list[i] >= 0:
            dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w - w_list[i]] + v_list[i])
        dp[i + 1][sum_w] = max(dp[i + 1][sum_w], dp[i][sum_w])

print(max(max(x.values()) for x in dp))


Fixed submission:
def main():
    N, W =  list(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):
            if dp[i] != -1 and dp[i + w] < dp[i] + v:
                dp[i + w] = dp[i] + v

    print(max(dp))

main()