#include<bits/stdc++.h>
#define it register int
#define ct const int
#define il inline
using namespace std;
typedef long long ll;
#define rll register ll
#define cll const ll
#define fir first
#define sec second
const int N=1000005;
namespace io{
	il char nc(){
		static char buf[100000],*p1=buf,*p2=buf;
		return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; 
	}
	template <class I> 
	il void fr(I &num){
		num=0;register char c=nc();it p=1;
		while(c<'0'||c>'9') c=='-'?p=-1,c=nc():c=nc();
		while(c>='0'&&c<='9') num=num*10+c-'0',c=nc();
		num*=p;
	}
	char obuf[1000001],*os=obuf, *ot=obuf+1000001;
	il void flush(){fwrite(obuf,1,os-obuf,stdout),os=obuf;}
	il void ptc(const char x){*os++=x,os==ot?flush():void();}
	template<class I>
	il void wr(I x){
		x<0?ptc('-'),x=-x:0;
		static char qu[65];
		char *tmp=qu;
		do *tmp++=(x%10)^'0';while(x/=10);
		while(tmp--!=qu) ptc(*tmp);
	}
	struct flusher{ ~flusher() { flush(); } }_;
}
using namespace io;
int n,a[N],lim;
vector<ll> b;
ll ans,K;
template<class I>
il void ckMax(I&p,I q){p=(p>q?p:q);}
il void dfs1(ct x,cll num){
	if(x>lim) return b.push_back(num),void();
	dfs1(x+1,num),dfs1(x+1,num+a[x]);
}
il void dfs2(ct x,cll num){
	//printf("x=%d num=%lld\n",x,num);
	//if(x>n&&num==a[7]) printf("%lld\n",*prev(std::upper_bound(b.begin(),b.end(),K-num)));
	if(x>n) return num<=K?ckMax(ans,num),0:0,K-num>=b[0]?ckMax(ans,*prev(std::upper_bound(b.begin(),b.end(),K-num))+num),0:0,void();
	dfs2(x+1,num),dfs2(x+1,num+a[x]);
}
int main(){ 
	scanf("%d%lld",&n,&K);it i;
	for(i=1;i<=n;++i) scanf("%d",&a[i]);
	ans=0,lim=n>>1,dfs1(1,0),std::sort(b.begin(),b.end()),dfs2(lim+1,0);
	//for(const auto &i : b) printf("%lld ",i);puts("");
	printf("%lld",ans);
	return 0;
}
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, s, n) for (ll i = s; i < (n); i++)

const ll INF = 1ll<<60;
class SegmentTree {
  ll n;
  // parent of k : (k-1)/2, child of k : 2*k+1, 2*k+2
  vector<ll> node;
  
public:
  SegmentTree(vector<ll> a){
    ll n_ = a.size();
    
    // round to power of 2
    n = 1;
    while(n < n_) n *= 2;
    
    // initialize tree
    node.resize(2*n-1, INF);
    
    // fill data into tree
    for (ll i = 0; i < n_; i++) node[n-1+i] = a[i];
    for (ll i = n-2; i >= 0; i--) node[i] = min(node[2*i+1], node[2*i+2]);
  }
  
  // [3, 4, 2, 1] RMQ(0, 3) -> 2, RMQ(0, 4) -> 1
  ll RMQ(ll a, ll b, ll k=0, ll l=0, ll r=-1){
    if (r<0) r = n;
    if (r<=a || b<=l) return INF;
    if (a<=l && r<=b) return node[k];
    ll vl = RMQ(a, b, 2*k+1, l, (l+r)/2);
    ll vr = RMQ(a, b, 2*k+2, (l+r)/2, r);
    return min(vl, vr);
  }
  
  // k番目をvにする
  void update(ll k, ll v){
    k += n-1;
    node[k] = v;
    while(k>0){
      k = (k-1)/2;
      node[k] = min(node[k*2+1], node[k*2+2]);
    }
  }
};

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n), b(n);
  rep(i, n) cin >> a[i];
  rep(i, n) cin >> b[i];
  ll now = 0;
  ll amax = 0;
  rep(i, n){
    amax = max(amax, a[i]);
    now = max(now, amax*b[i]);
    cout << now << endl;
  }
  
  return 0;
}