import sys

sys.setrecursionlimit(10**9)

input = lambda: sys.stdin.readline().rstrip()

inpl = lambda: list(map(int,input().split()))

N, T = inpl()

A = [None]*N

B = [None]*N

for i in range(N):

    A[i], B[i] = inpl()



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

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

for n in range(1,N+1):

    for t in range(T):

        if A[n-1] > t:

            dp_intime[n][t] = dp_intime[n-1][t]

            dp_total[n][t] = max(B[n-1]+dp_intime[n-1][t], dp_total[n-1][t])

        else:

            dp_intime[n][t] = max(dp_intime[n-1][t], B[n-1]+dp_intime[n-1][t-A[n-1]])

            dp_total[n][t] = max(B[n-1]+dp_intime[n-1][t],

                                 B[n-1]+dp_total[n-1][t-A[n-1]],

                                 dp_total[n-1][t])

print((dp_total[-1][-1]))
import sys

input = lambda: sys.stdin.readline().rstrip()

inpl = lambda: list(map(int,input().split()))

N, T = inpl()

A = [None]*N

B = [None]*N

for i in range(N):

    A[i], B[i] = inpl()



dp_intime = [0]*T

dp_total = [0]*T

for n in range(N):

    dp_intime_prev, dp_intime = dp_intime, [0]*T

    dp_total_prev, dp_total = dp_total, [0]*T

    for t in range(T):

        if A[n] > t:

            dp_intime[t] = dp_intime_prev[t]

            dp_total[t] = max(B[n]+dp_intime_prev[t], dp_total_prev[t])

        else:

            dp_intime[t] = max(dp_intime_prev[t], B[n]+dp_intime_prev[t-A[n]])

            dp_total[t] = max(B[n]+dp_intime_prev[t],

                              B[n]+dp_total_prev[t-A[n]],

                              dp_total_prev[t])

print((dp_total[-1]))
import sys

sys.setrecursionlimit(10**9)
input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int, input().split()))
N, T = inpl()
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = inpl()
dp_intime = [[0] * T for _ in range(N + 1)]
dp_total = [[0] * T for _ in range(N + 1)]
for n in range(1, N + 1):
    for t in range(T):
        if A[n - 1] > t:
            dp_intime[n][t] = dp_intime[n - 1][t]
            dp_total[n][t] = max(B[n - 1] + dp_intime[n - 1][t], dp_total[n - 1][t])
        else:
            dp_intime[n][t] = max(
                dp_intime[n - 1][t], B[n - 1] + dp_intime[n - 1][t - A[n - 1]]
            )
            dp_total[n][t] = max(
                B[n - 1] + dp_intime[n - 1][t],
                B[n - 1] + dp_total[n - 1][t - A[n - 1]],
                dp_total[n - 1][t],
            )
print((dp_total[-1][-1]))

import sys

input = lambda: sys.stdin.readline().rstrip()
inpl = lambda: list(map(int, input().split()))
N, T = inpl()
A = [None] * N
B = [None] * N
for i in range(N):
    A[i], B[i] = inpl()
dp_intime = [0] * T
dp_total = [0] * T
for n in range(N):
    dp_intime_prev, dp_intime = dp_intime, [0] * T
    dp_total_prev, dp_total = dp_total, [0] * T
    for t in range(T):
        if A[n] > t:
            dp_intime[t] = dp_intime_prev[t]
            dp_total[t] = max(B[n] + dp_intime_prev[t], dp_total_prev[t])
        else:
            dp_intime[t] = max(dp_intime_prev[t], B[n] + dp_intime_prev[t - A[n]])
            dp_total[t] = max(
                B[n] + dp_intime_prev[t],
                B[n] + dp_total_prev[t - A[n]],
                dp_total_prev[t],
            )
print((dp_total[-1]))

-sys.setrecursionlimit(10**9) -dp_intime = [[0] * T for _ in range(N + 1)] -dp_total = [[0] * T for _ in range(N + 1)] -for n in range(1, N + 1): +dp_intime = [0] * T +dp_total = [0] * T +for n in range(N): +    dp_intime_prev, dp_intime = dp_intime, [0] * T +    dp_total_prev, dp_total = dp_total, [0] * T -        if A[n - 1] > t: -            dp_intime[n][t] = dp_intime[n - 1][t] -            dp_total[n][t] = max(B[n - 1] + dp_intime[n - 1][t], dp_total[n - 1][t]) +        if A[n] > t: +            dp_intime[t] = dp_intime_prev[t] +            dp_total[t] = max(B[n] + dp_intime_prev[t], dp_total_prev[t]) -            dp_intime[n][t] = max( -                dp_intime[n - 1][t], B[n - 1] + dp_intime[n - 1][t - A[n - 1]] +            dp_intime[t] = max(dp_intime_prev[t], B[n] + dp_intime_prev[t - A[n]]) +            dp_total[t] = max( +                B[n] + dp_intime_prev[t], +                B[n] + dp_total_prev[t - A[n]], +                dp_total_prev[t], -            dp_total[n][t] = max( -                B[n - 1] + dp_intime[n - 1][t], -                B[n - 1] + dp_total[n - 1][t - A[n - 1]], -                dp_total[n - 1][t], -            ) -print((dp_total[-1][-1])) +print((dp_total[-1]))