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

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



dp = [[0] * (T + 1) for _ in range(N + 1)]

for i, (a, b) in enumerate(sorted(X)):

    for j in range(T + 1):

        if j == T:

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

        elif j < a:

            dp[i + 1][j] = dp[i][j]

        else:

            dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b)

            

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

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

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



dp = [-1] * 6001

dp[0] = 0

for a, b in sorted(X):

    for j in reversed(list(range(T))):

        if dp[j] == -1:

            continue



        dp[j + a] = max(dp[j + a], dp[j] + b)

            

print((max(dp)))

N, T = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
dp = [[0] * (T + 1) for _ in range(N + 1)]
for i, (a, b) in enumerate(sorted(X)):
    for j in range(T + 1):
        if j == T:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - 1] + b)
        elif j < a:
            dp[i + 1][j] = dp[i][j]
        else:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b)
print((dp[-1][-1]))

N, T = list(map(int, input().split()))
X = [list(map(int, input().split())) for _ in range(N)]
dp = [-1] * 6001
dp[0] = 0
for a, b in sorted(X):
    for j in reversed(list(range(T))):
        if dp[j] == -1:
            continue
        dp[j + a] = max(dp[j + a], dp[j] + b)
print((max(dp)))

-dp = [[0] * (T + 1) for _ in range(N + 1)] -for i, (a, b) in enumerate(sorted(X)): -    for j in range(T + 1): -        if j == T: -            dp[i + 1][j] = max(dp[i][j], dp[i][j - 1] + b) -        elif j < a: -            dp[i + 1][j] = dp[i][j] -        else: -            dp[i + 1][j] = max(dp[i][j], dp[i][j - a] + b) -print((dp[-1][-1])) +dp = [-1] * 6001 +dp[0] = 0 +for a, b in sorted(X): +    for j in reversed(list(range(T))): +        if dp[j] == -1: +            continue +        dp[j + a] = max(dp[j + a], dp[j] + b) +print((max(dp)))