Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    Knap = [[0] * (w+1) for _ in range(n+1)]

    for i in range(n):
        for j in reversed(range(i+1)):
            for k in range(w+1):
#                if (Knap[j][k] > 0 or (j == 0 and k ==0)) and k + A[i][0] <= w:
                point = k + A[i][0]
                if point <= w:
                    Knap[j+1][k + A[i][0]] = max((Knap[j+1][point]), (Knap[j][k] + A[i][1]))

    knapmax = 0
    for i in range(n):
        knapmax = max(knapmax, max(Knap[i+1]))
    print(knapmax)

resolve()

Fixed submission:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    Knap = [[0] * (w+1) for _ in range(n+1)]
#    Knap = [[0] * (110) for _ in range(10**5+10)]

    for i in range(n):
        for k in range(w+1):
            if k + A[i][0] <= w:
#                point = k + A[i][0]
                Knap[i+1][k+A[i][0]] = max(Knap[i+1][k+A[i][0]], (Knap[i][k] + A[i][1]))

            Knap[i+1][k] = max(Knap[i][k], Knap[i+1][k])

#    knapmax = 0
    # for i in range(n):
    #     knapmax = max(knapmax, max(Knap[i+1]))
    print(Knap[n][w])
#    print(*Knap, sep="\n")
resolve()

Buggy python submission (verdict: Time Limit Exceeded):
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    Knap = [[0] * (w+1) for _ in range(n+1)]

    for i in range(n):
        for j in reversed(range(i+1)):
            for k in range(w+1):
                if (Knap[j][k] > 0 or (j == 0 and k ==0)) and k + A[i][0] <= w:
                    Knap[j+1][k + A[i][0]] = max((Knap[j+1][k + A[i][0]]), (Knap[j][k] + A[i][1]))

    knapmax = 0
    for i in range(n):
        knapmax = max(knapmax, max(Knap[i+1]))
    print(knapmax)

resolve()

Fixed submission:
def resolve():
    import sys
    input = sys.stdin.readline
    # 整数 1 つ
    # n = int(input())
    # 整数複数個
    n, w = map(int, input().split())
    # 整数 N 個 (改行区切り)
    # N = [int(input()) for i in range(N)]
    # 整数 N 個 (スペース区切り)
    # N = list(map(int, input().split()))
    # 整数 (縦 H 横 W の行列)
    A = [list(map(int, input().split())) for i in range(n)]

    Knap = [[0] * (w+1) for _ in range(n+1)]
#    Knap = [[0] * (110) for _ in range(10**5+10)]

    for i in range(n):
        for k in range(w+1):
            if k + A[i][0] <= w:
#                point = k + A[i][0]
                Knap[i+1][k+A[i][0]] = max(Knap[i+1][k+A[i][0]], (Knap[i][k] + A[i][1]))

            Knap[i+1][k] = max(Knap[i][k], Knap[i+1][k])

#    knapmax = 0
    # for i in range(n):
    #     knapmax = max(knapmax, max(Knap[i+1]))
    print(Knap[n][w])
#    print(*Knap, sep="\n")
resolve()