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

wv=[]

dp=[[0 for i in range(100010)]for j in range(110)]

for i in range(n):

    a=[int(j) for j in input().split()]

    wv.append(a)



from operator import itemgetter

wv.sort(key=itemgetter(0))



for i in range(n):

    for j in range(w+1):

        if j>=wv[i][0]:

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

        else:

            dp[i+1][j]=dp[i][j]





print((dp[n][w]))
n,W=[int(j) for j in input().split()]

wv=[[int(j) for j in input().split()]for i in range(n)]

import numpy as np

dp=np.zeros(W+1,dtype=np.int64)

for w,v in wv:

    dp[w:]=np.maximum(dp[w:],dp[:-w]+v)

print((dp.max()))
n, w = list(map(int, input().split()))
wv = []
dp = [[0 for i in range(100010)] for j in range(110)]
for i in range(n):
    a = [int(j) for j in input().split()]
    wv.append(a)
from operator import itemgetter

wv.sort(key=itemgetter(0))
for i in range(n):
    for j in range(w + 1):
        if j >= wv[i][0]:
            dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1])
        else:
            dp[i + 1][j] = dp[i][j]
print((dp[n][w]))

n, W = [int(j) for j in input().split()]
wv = [[int(j) for j in input().split()] for i in range(n)]
import numpy as np

dp = np.zeros(W + 1, dtype=np.int64)
for w, v in wv:
    dp[w:] = np.maximum(dp[w:], dp[:-w] + v)
print((dp.max()))

-n, w = list(map(int, input().split())) -wv = [] -dp = [[0 for i in range(100010)] for j in range(110)] -for i in range(n): -    a = [int(j) for j in input().split()] -    wv.append(a) -from operator import itemgetter +n, W = [int(j) for j in input().split()] +wv = [[int(j) for j in input().split()] for i in range(n)] +import numpy as np -wv.sort(key=itemgetter(0)) -for i in range(n): -    for j in range(w + 1): -        if j >= wv[i][0]: -            dp[i + 1][j] = max(dp[i][j], dp[i][j - wv[i][0]] + wv[i][1]) -        else: -            dp[i + 1][j] = dp[i][j] -print((dp[n][w])) +dp = np.zeros(W + 1, dtype=np.int64) +for w, v in wv: +    dp[w:] = np.maximum(dp[w:], dp[:-w] + v) +print((dp.max()))