1#include<bits/stdc++.h>
2using namespace std;
3vector<pair<int,int> >a;
4//dp table is full of zeros
5int n,s,dp[1002][1002];
6void ini(){
7 for(int i=0;i<1002;i++)
8 for(int j=0;j<1002;j++)
9 dp[i][j]=-1;
10}
11int f(int x,int b){
12 //base solution
13 if(x>=n or b<=0)return 0;
14 //if we calculate this before, we just return the answer (value diferente of 0)
15 if(dp[x][b]!=-1)return dp[x][b];
16 //calculate de answer for x (position) and b(empty space in knapsack)
17 //we get max between take it or not and element, this gonna calculate all the
18 //posible combinations, with dp we won't calculate what is already calculated.
19 return dp[x][b]=max(f(x+1,b),b-a[x].second>=0?f(x+1,b-a[x].second)+a[x].first:INT_MIN);
20}
21int main(){
22 //fast scan and print
23 ios_base::sync_with_stdio(0);cin.tie(0);
24 //we obtain quantity of elements and size of knapsack
25 cin>>n>>s;
26 a.resize(n);
27 //we get value of elements
28 for(int i=0;i<n;i++)
29 cin>>a[i].first;
30 //we get size of elements
31 for(int i=0;i<n;i++)
32 cin>>a[i].second;
33 //initialize dp table
34 ini();
35 //print answer
36 cout<<f(0,s);
37 return 0;
38}
39