N, W = list(map(int, input().split()))

goods = []

for _ in range(N):

    goods.append(tuple(map(int, input().split())))



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

for n in range(N):

    for w in range(W + 1):

        addn = table[n][w - goods[n][0]] + goods[n][1] if w - goods[n][0] >= 0 else 0

        table[n + 1][w] = max(table[n][w], addn)

print((table[N][W]))

import numpy as np



N, W = list(map(int, input().split()))

goods = [tuple(map(int, input().split())) for _ in range(N)]



dp = np.zeros(W + 1, dtype=np.int64)

for n in range(N):

    tmp = np.zeros_like(dp, dtype=np.int64)

    tmp[goods[n][0]:] = dp[:W + 1 - goods[n][0]] + goods[n][1]

    dp = np.maximum(dp, tmp)

print((dp[W]))

N, W = list(map(int, input().split()))
goods = []
for _ in range(N):
    goods.append(tuple(map(int, input().split())))
table = [[0] * (W + 1) for _ in range(N + 1)]
for n in range(N):
    for w in range(W + 1):
        addn = table[n][w - goods[n][0]] + goods[n][1] if w - goods[n][0] >= 0 else 0
        table[n + 1][w] = max(table[n][w], addn)
print((table[N][W]))

import numpy as np

N, W = list(map(int, input().split()))
goods = [tuple(map(int, input().split())) for _ in range(N)]
dp = np.zeros(W + 1, dtype=np.int64)
for n in range(N):
    tmp = np.zeros_like(dp, dtype=np.int64)
    tmp[goods[n][0] :] = dp[: W + 1 - goods[n][0]] + goods[n][1]
    dp = np.maximum(dp, tmp)
print((dp[W]))

+import numpy as np + -goods = [] -for _ in range(N): -    goods.append(tuple(map(int, input().split()))) -table = [[0] * (W + 1) for _ in range(N + 1)] +goods = [tuple(map(int, input().split())) for _ in range(N)] +dp = np.zeros(W + 1, dtype=np.int64) -    for w in range(W + 1): -        addn = table[n][w - goods[n][0]] + goods[n][1] if w - goods[n][0] >= 0 else 0 -        table[n + 1][w] = max(table[n][w], addn) -print((table[N][W])) +    tmp = np.zeros_like(dp, dtype=np.int64) +    tmp[goods[n][0] :] = dp[: W + 1 - goods[n][0]] + goods[n][1] +    dp = np.maximum(dp, tmp) +print((dp[W]))