#include <bits/stdc++.h>
using namespace std;
#define int              long long int
#define double           long double


const int M = 1000000007;
const int N = 3e5+9;
const int INF = 2e9+1;
const int MAXN = 100000;
const int LINF = 2000000000000000001;

//_ ***************************** START Below *******************************



vector<int> a;
vector<int>b;


int consistency(int n, int k){
	int ans = 0;
	
	int s = 0, e = 0;
	int weights = 0;
	int costs = 0;
	
	while(e<n){
		weights += a[e];
		costs += b[e];
		
		if(weights < k){
			ans = max(ans, costs);
			e++;
		}
		else{
			while(s<=e && weights > k){
				weights -= a[s];
				costs -= b[s];
				s++;
			}
			ans = max(ans, costs);
			e++;
		}
	}

	return ans;

}






 
 
 


void solve() {

	int n, k;
	cin >> n >> k;
	a.resize(n);
	b.resize(n);
	for(int i=0; i<n; i++) cin >> a[i];
	for(int i=0; i<n; i++) cin >> b[i];

	cout << consistency(n, k) << endl;
	
	
	
	
}





int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int t = 1;
    while (t--) {
        solve();
    }

    return 0;
}