Buggy python submission (verdict: Time Limit Exceeded):
def main(N, W, P):
    dp = [[0]*(W + 1) for _ in range(N)]
    for j in range(P[0][0], W+1):
        dp[0][j] = P[0][1]

    for i in range(1, N):
        for j in range(1, W + 1):
            if j - P[i][0] < 0:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
                continue

            dp[i][j] = max(dp[i-1][j-P[i][0]] + P[i][1],
                        dp[i-1][j])

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

if __name__ == "__main__":
    N, W = map(int, input().split()) #N個の製品、Wの制限
    P = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, W, P)

Fixed submission:
def main(N, W, P):
    dp = [[0]*(W + 1) for _ in range(N)]
    for j in range(P[0][0], W+1):
        dp[0][j] = P[0][1]

    for i in range(1, N):
        for j in range(1, W + 1):
            if j - P[i][0] < 0:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
                continue

            dp[i][j] = max(dp[i-1][j-P[i][0]] + P[i][1],
                           dp[i-1][j])

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

if __name__ == "__main__":
    N, W = map(int, input().split()) #N個の製品、Wの制限
    P = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, W, P)

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split()) #N個の製品、Wの制限
P = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W + 1) for _ in range(N)]

for j in range(P[0][0], W+1):
    dp[0][j] = P[0][1]

for i in range(1, N):
    for j in range(1, W + 1):
        if j - P[i][0] < 0:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
            continue

        dp[i][j] = max(dp[i-1][j-P[i][0]] + P[i][1],
                       dp[i-1][j])

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

Fixed submission:
def main(N, W, P):
    dp = [[0]*(W + 1) for _ in range(N)]
    for j in range(P[0][0], W+1):
        dp[0][j] = P[0][1]

    for i in range(1, N):
        for j in range(1, W + 1):
            if j - P[i][0] < 0:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
                continue

            dp[i][j] = max(dp[i-1][j-P[i][0]] + P[i][1],
                           dp[i-1][j])

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

if __name__ == "__main__":
    N, W = map(int, input().split()) #N個の製品、Wの制限
    P = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, W, P)

Buggy python submission (verdict: Time Limit Exceeded):
N, W = map(int, input().split()) #N個の製品、Wの制限
P = [tuple(map(int, input().split())) for _ in range(N)]
dp = [[0]*(W + 1) for _ in range(N)]

for j in range(P[0][0], W+1):
    dp[0][j] = P[0][1]

for i in range(1, N):
    for j in range(1, W + 1):
        if j - P[i][0] < 0:
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
            continue

        dp[i][j] = max(dp[i-1][j-P[i][0]] + P[i][1],
                       dp[i-1][j],
                       dp[i][j-1])

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

Fixed submission:
def main(N, W, P):
    dp = [[0]*(W + 1) for _ in range(N)]
    for j in range(P[0][0], W+1):
        dp[0][j] = P[0][1]

    for i in range(1, N):
        for j in range(1, W + 1):
            if j - P[i][0] < 0:
                dp[i][j] = max(dp[i-1][j], dp[i][j-1])
                continue

            dp[i][j] = max(dp[i-1][j-P[i][0]] + P[i][1],
                           dp[i-1][j])

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

if __name__ == "__main__":
    N, W = map(int, input().split()) #N個の製品、Wの制限
    P = [tuple(map(int, input().split())) for _ in range(N)]
    main(N, W, P)