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

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

ab.sort()

dp=[(6007)*[0]for _ in range(n+1)]

dp[0][0]=0

ans=0

for i in range(n):

  for j in range(6007):

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

    if j<t:dp[i+1][j+ab[i][0]]=max(dp[i][j]+ab[i][1],dp[i][j+ab[i][0]])

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

print(ans)

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

dp=[[0]*(t+3001)for _ in range(n+1)]

ans=0

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

ab.sort()

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

    a,b=ab[i-1]

    for j in range(t):

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

        dp[i][j+a]=dp[i-1][j]+b

        ans=max(dp[i][j],dp[i][j+a],ans)

print(ans)   
n, t = list(map(int, input().split()))
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
dp = [(6007) * [0] for _ in range(n + 1)]
dp[0][0] = 0
ans = 0
for i in range(n):
    for j in range(6007):
        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
        if j < t:
            dp[i + 1][j + ab[i][0]] = max(dp[i][j] + ab[i][1], dp[i][j + ab[i][0]])
        ans = max(ans, dp[i + 1][j])
print(ans)

n, t = list(map(int, input().split()))
dp = [[0] * (t + 3001) for _ in range(n + 1)]
ans = 0
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
for i in range(1, n + 1):
    a, b = ab[i - 1]
    for j in range(t):
        dp[i][j] = max(dp[i - 1][j], dp[i][j])
        dp[i][j + a] = dp[i - 1][j] + b
        ans = max(dp[i][j], dp[i][j + a], ans)
print(ans)

+dp = [[0] * (t + 3001) for _ in range(n + 1)] +ans = 0 -dp = [(6007) * [0] for _ in range(n + 1)] -dp[0][0] = 0 -ans = 0 -for i in range(n): -    for j in range(6007): -        dp[i + 1][j] = max(dp[i + 1][j], dp[i][j]) -        if j < t: -            dp[i + 1][j + ab[i][0]] = max(dp[i][j] + ab[i][1], dp[i][j + ab[i][0]]) -        ans = max(ans, dp[i + 1][j]) +for i in range(1, n + 1): +    a, b = ab[i - 1] +    for j in range(t): +        dp[i][j] = max(dp[i - 1][j], dp[i][j]) +        dp[i][j + a] = dp[i - 1][j] + b +        ans = max(dp[i][j], dp[i][j + a], ans)