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]))
inpl = lambda: list(map(int,input().split()))

N, T = inpl()

AB = sorted([inpl() for _ in range(N)])



ans = 0

dp_intime = [0]*T

for n in range(N):

    dp_intime_prev = dp_intime

    dp_intime = [0]*T

    a, b = AB[n]

    for t in range(T):

        if t < a:

            dp_intime[t] = dp_intime_prev[t]

        else:

            dp_intime[t] = max(dp_intime_prev[t], dp_intime_prev[t-a]+b)

    ans = max(ans, dp_intime_prev[-1]+b)

print(ans)
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]))

inpl = lambda: list(map(int, input().split()))
N, T = inpl()
AB = sorted([inpl() for _ in range(N)])
ans = 0
dp_intime = [0] * T
for n in range(N):
    dp_intime_prev = dp_intime
    dp_intime = [0] * T
    a, b = AB[n]
    for t in range(T):
        if t < a:
            dp_intime[t] = dp_intime_prev[t]
        else:
            dp_intime[t] = max(dp_intime_prev[t], dp_intime_prev[t - a] + b)
    ans = max(ans, dp_intime_prev[-1] + b)
print(ans)

-import sys - -input = lambda: sys.stdin.readline().rstrip() -A = [None] * N -B = [None] * N -for i in range(N): -    A[i], B[i] = inpl() +AB = sorted([inpl() for _ in range(N)]) +ans = 0 -dp_total = [0] * T -    dp_intime_prev, dp_intime = dp_intime, [0] * T -    dp_total_prev, dp_total = dp_total, [0] * T +    dp_intime_prev = dp_intime +    dp_intime = [0] * T +    a, b = AB[n] -        if A[n] > t: +        if t < a: -            dp_total[t] = max(B[n] + dp_intime_prev[t], dp_total_prev[t]) -            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])) +            dp_intime[t] = max(dp_intime_prev[t], dp_intime_prev[t - a] + b) +    ans = max(ans, dp_intime_prev[-1] + b) +print(ans)