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)]

ans=0

for i in range(n):

  a,b=ab[i]

  for j in range(6007):

    if i==0:

      if j>=a and j<t:dp[i][j]=b

    elif j>=a and j-a<t:dp[i][j]=max(dp[i-1][j-a]+b,dp[i-1][j])

    else:dp[i][j]=dp[i-1][j]

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

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)]

for i in range(n):

  a,b=ab[i]

  for j in range(6007):

    if i==0:

      if j>=a and j<t:dp[i][j]=b

    elif j>=a and j-a<t:dp[i][j]=max(dp[i-1][j-a]+b,dp[i-1][j])

    else:dp[i][j]=dp[i-1][j]

print((max(dp[-1])))
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)]
ans = 0
for i in range(n):
    a, b = ab[i]
    for j in range(6007):
        if i == 0:
            if j >= a and j < t:
                dp[i][j] = b
        elif j >= a and j - a < t:
            dp[i][j] = max(dp[i - 1][j - a] + b, dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]
        ans = max(ans, dp[i][j])
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)]
for i in range(n):
    a, b = ab[i]
    for j in range(6007):
        if i == 0:
            if j >= a and j < t:
                dp[i][j] = b
        elif j >= a and j - a < t:
            dp[i][j] = max(dp[i - 1][j - a] + b, dp[i - 1][j])
        else:
            dp[i][j] = dp[i - 1][j]
print((max(dp[-1])))

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