#include <bits/stdc++.h>
#define task ""
#define endl 'n'
#define MASK(i) (1LL << (i))
#define c_bit(i) __builtin_popcountll(i)
#define BIT(x, i) ((x) & MASK(i))
#define SET_ON(x, i) ((x) | MASK(i))
#define SET_OFF(x, i) ((x) &~ MASK(i))
#define int long long
using namespace std;
const int oo=1e18;
int n,k;
int a[500],b[500],f[200][200];
int dp(int id,int last)
{
if (id > n)
return 0;
if (f[id][last] != -1)
return f[id][last];
int res = 0;
if (a[id] - a[last] >= k)
res = max(res,dp(id + 1,id) + b[id]);
res = max(res,dp(id + 1,last));
return f[id][last] = res;
}
main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// freopen(task".inp","r",stdin);
// freopen(task".out","w",stdout);
memset(f,-1,sizeof f);
cin>>n>>k;
for (int i = 1;i <= n;i++)
cin>>a[i];
for (int i = 1;i <= n;i++)
cin>>b[i];
a[0] = -100;
cout<<dp(1,0);
}