from collections import defaultdict





n, t = list(map(int, input().split()))



dish = []



for _ in range(n):

    time, point = list(map(int, input().split()))

    dish.append([time, point])



dish.sort()

DP = [[0]*t for i in range(n+1)]

ans = defaultdict(int)



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

    time, point = dish[i-1]



    for j in range(t):

        DP[i][j] = max(DP[i-1][j], DP[i][j])

        if j + time >= t:

            ans[i] = max(DP[i-1][j]+point, ans[i])

            continue

        DP[i][j+time] = max((DP[i-1][j] + point), DP[i-1][j+time])



res = max(ans.values())

print(res)
import numpy as np

import sys

input = sys.stdin.readline





n, t = list(map(int, input().split()))

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

dish.sort()



ans = 0

dp = np.zeros(t, dtype=int)

for time, point in dish:

    ans = max(ans, dp.max()+point)

    np.maximum(dp[time:], dp[:-time]+point, out=dp[time:])

print(ans)
from collections import defaultdict

n, t = list(map(int, input().split()))
dish = []
for _ in range(n):
    time, point = list(map(int, input().split()))
    dish.append([time, point])
dish.sort()
DP = [[0] * t for i in range(n + 1)]
ans = defaultdict(int)
for i in range(1, n + 1):
    time, point = dish[i - 1]
    for j in range(t):
        DP[i][j] = max(DP[i - 1][j], DP[i][j])
        if j + time >= t:
            ans[i] = max(DP[i - 1][j] + point, ans[i])
            continue
        DP[i][j + time] = max((DP[i - 1][j] + point), DP[i - 1][j + time])
res = max(ans.values())
print(res)

import numpy as np
import sys

input = sys.stdin.readline
n, t = list(map(int, input().split()))
dish = [list(map(int, input().split())) for _ in range(n)]
dish.sort()
ans = 0
dp = np.zeros(t, dtype=int)
for time, point in dish:
    ans = max(ans, dp.max() + point)
    np.maximum(dp[time:], dp[:-time] + point, out=dp[time:])
print(ans)

-from collections import defaultdict +import numpy as np +import sys +input = sys.stdin.readline -dish = [] -for _ in range(n): -    time, point = list(map(int, input().split())) -    dish.append([time, point]) +dish = [list(map(int, input().split())) for _ in range(n)] -DP = [[0] * t for i in range(n + 1)] -ans = defaultdict(int) -for i in range(1, n + 1): -    time, point = dish[i - 1] -    for j in range(t): -        DP[i][j] = max(DP[i - 1][j], DP[i][j]) -        if j + time >= t: -            ans[i] = max(DP[i - 1][j] + point, ans[i]) -            continue -        DP[i][j + time] = max((DP[i - 1][j] + point), DP[i - 1][j + time]) -res = max(ans.values()) -print(res) +ans = 0 +dp = np.zeros(t, dtype=int) +for time, point in dish: +    ans = max(ans, dp.max() + point) +    np.maximum(dp[time:], dp[:-time] + point, out=dp[time:]) +print(ans)