Buggy python submission (verdict: Time Limit Exceeded):
#!/usr/bin/env python3
def main():
    import numpy as np

    np.set_printoptions(linewidth=200)

    N, W = map(int, input().split())
    lst = [list(map(int, input().split())) for _ in range(N)]
    v_max = 10 ** 3 * 100 * 10
    w_max = 10 ** 9 * v_max
    # v_max = 150
    # v_max = 30

    # i以上の価値を持つときの最小重量
    dp = np.full((N + 1, v_max), w_max, dtype=np.int64)
    # initialize
    # w, v = lst[0]
    # dp[0][v:] = w
    dp[0][0] = 0
    for n in range(N):
        w, v = lst[n]
        dp[n + 1, v:] = np.minimum(dp[n + 1, v:], dp[n, :-v] + w)
        dp[n + 1, :] = np.minimum(dp[n + 1, :], dp[n, :])

    ans = 0
    for i, w in enumerate(dp[-1]):
        if w <= W:
            ans = i
    print(ans)
    # print(dp)


if __name__ == '__main__':
    main()


Fixed submission:
import sys


def resolve():
    readline = sys.stdin.readline

    N, W = map(int, readline().split())
    lst = [list(map(int, readline().split())) for x in [0] * N]

    # 配るDP
    # dp[i][sum_v]はi個の品物の内でsum_v以上となる最小の重量
    V = N * 10 ** 3 + 1  # 価値の最大値
    inf = 10 ** 10
    dp = [[inf] * V for _ in [0] * (N + 1)]
    dp[0][0] = 0

    for i in range(N):
        for sum_v in range(V):
            weight, value = lst[i]
            if sum_v - value >= 0:
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v],
                                       dp[i][sum_v - value] + weight)
            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0
    for sum_v in range(V):
        if dp[N][sum_v] <= W:
            ans = sum_v
    print(ans)
    

resolve()

Buggy python submission (verdict: Time Limit Exceeded):
import sys


def resolve():
    readline = sys.stdin.readline

    N, W = map(int, readline().split())
    lst = [list(map(int, readline().split())) for x in [0] * N]

    # 配るDP
    # dp[i][sum_v]はi個の品物の内でsum_v以上となる最小の重量
    V = N * 10 ** 3 + 1  # 価値の最大値
    inf = 10 ** 10
    dp = [[inf] * V for _ in [0] * (N + 1)]
    dp[0][0] = 0

    for i in range(N):
        for sum_v in range(V):
            weight, value = lst[i]
            if sum_v - value >= 0:
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v],
                                       dp[i][sum_v - value] + weight)
            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0
    for sum_v in range(V):
        if dp[N][sum_v] <= W:
            ans = sum_v
    print(ans)
    

resolve()


Fixed submission:
import sys


def resolve():
    readline = sys.stdin.readline

    N, W = map(int, readline().split())
    lst = [list(map(int, readline().split())) for x in [0] * N]

    # 配るDP
    # dp[i][sum_v]はi個の品物の内でsum_v以上となる最小の重量
    V = N * 10 ** 3 + 1  # 価値の最大値
    inf = 10 ** 10
    dp = [[inf] * V for _ in [0] * (N + 1)]
    dp[0][0] = 0

    for i in range(N):
        for sum_v in range(V):
            weight, value = lst[i]
            if sum_v - value >= 0:
                dp[i + 1][sum_v] = min(dp[i + 1][sum_v],
                                       dp[i][sum_v - value] + weight)
            dp[i + 1][sum_v] = min(dp[i + 1][sum_v], dp[i][sum_v])

    ans = 0
    for sum_v in range(V):
        if dp[N][sum_v] <= W:
            ans = sum_v
    print(ans)
    

resolve()