#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include<stack>
#include <iomanip>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define per(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define mst(a,b) memset(a,b,sizeof(a));
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf=0x3f3f3f3f;
const int maxn=2e5+7;
int a[maxn];
int b[maxn];
int sum[maxn];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
 	//std::ios::sync_with_stdio(false);
    //cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&a[i]);
    	sum[i]=sum[i-1]+a[i];
    }
    priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
    	if(sum[i]<=m)
    	{
    		printf("0\n");
    		q.push(a[i]);
    	}
    	else
    	{
    		int tp=sum[i];
    		int ans=0;
    		int r=0;
    		while(!q.empty()&&tp>m)
    		{
    			b[r]=q.top();
    			q.pop();
    			tp-=b[r];
    			r++;
    			ans++;
    		}
    		for(int j=0;j<r;j++)
    		{
    			q.push(b[j]);
    		}
    		q.push(a[i]);
    		printf("%d\n",ans);
    	}
    }
    return 0;

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include<stack>
#include <iomanip>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define per(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define mst(a,b) memset(a,b,sizeof(a));
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf=0x3f3f3f3f;
const int maxn=2e5+7;
int a[maxn];
int b[maxn];
int sum[maxn];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
 	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    	sum[i]=sum[i-1]+a[i];
    }
    priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
    	if(sum[i]<=m)
    	{
    		cout<<"0"<<endl;
    		q.push(a[i]);
    	}
    	else
    	{
    		int tp=sum[i];
    		int ans=0;
    		int r=0;
    		while(!q.empty()&&tp>m)
    		{
    			b[r]=q.top();
    			q.pop();
    			tp-=b[r];
    			r++;
    			ans++;
    		}
    		for(int j=0;j<r;j++)
    		{
    			q.push(b[j]);
    		}
    		q.push(a[i]);
    		cout<<ans<<endl;
    	}
    }
    return 0;

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include<stack>
#include <iomanip>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define per(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define mst(a,b) memset(a,b,sizeof(a));
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf=0x3f3f3f3f;
const int maxn=2e5+7;
int a[maxn];
int b[maxn];
int c[maxn];
int sum[maxn];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
 	//std::ios::sync_with_stdio(false);
    //cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&a[i]);
    	sum[i]=sum[i-1]+a[i];
    }
    priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
    	if(sum[i]<=m)
    	{
    		printf("0\n");
    			if(c[a[i]]==0)
    		{
    			q.push(a[i]);
    		}
    		c[a[i]]++;

    	}
    	else
    	{
    		int tp=sum[i];
    		int ans=0;
    		int r=0;
    		while(!q.empty()&&tp>m)
    		{
    			b[r]=q.top();
    			q.pop();
    			if(c[b[r]]*b[r]>=(tp-m))
    			{
    				int k=((tp-m)-1)/(b[r])+1;
					tp-=(k*b[r]);
					ans+=k;
    			}
    			else
    			{
    				ans+=c[b[r]];
    				tp-=b[r];
    			}
    			r++;

    		}
    		for(int j=0;j<r;j++)
    		{
    			q.push(b[j]);
    		}
    			if(c[a[i]]==0)
    		{
    			q.push(a[i]);
    		}
    		c[a[i]]++;

    		printf("%d\n",ans);
    	}
    }
    return 0;

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include<stack>
#include <iomanip>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define per(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define mst(a,b) memset(a,b,sizeof(a));
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf=0x3f3f3f3f;
const int maxn=1e5+7;
int a[maxn];
int b[maxn];
int sum[maxn];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
 	std::ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	cin>>a[i];
    	sum[i]=sum[i-1]+a[i];
    }
    priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
    	if(sum[i]<=m)
    	{
    		cout<<"0"<<endl;
    		q.push(a[i]);
    	}
    	else
    	{
    		int tp=sum[i];
    		int ans=0;
    		int r=0;
    		while(!q.empty()&&tp>m)
    		{
    			b[r]=q.top();
    			q.pop();
    			tp-=b[r];
    			r++;
    			ans++;
    		}
    		for(int j=0;j<r;j++)
    		{
    			q.push(b[j]);
    		}
    		q.push(a[i]);
    		cout<<ans<<endl;
    	}
    }
    return 0;

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include<stack>
#include <iomanip>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define per(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define mst(a,b) memset(a,b,sizeof(a));
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf=0x3f3f3f3f;
const int maxn=2e5+7;
int a[maxn];
int b[maxn];
int c[maxn];
int sum[maxn];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
 	//std::ios::sync_with_stdio(false);
    //cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&a[i]);
    	sum[i]=sum[i-1]+a[i];
    }
    priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
    	if(sum[i]<=m)
    	{
    		printf("0\n");
    		if(c[a[i]]==0)
    		{
    			q.push(a[i]);
    		}
    		c[a[i]]++;

    	}
    	else
    	{
    		int tp=sum[i];
    		int ans=0;
    		int r=0;
    		while(!q.empty()&&tp>m)
    		{
    			b[r]=q.top();
    			q.pop();
    			if(c[b[r]]*b[r]>=(tp-m))
    			{
    				int k=((tp-m)-1)/(b[r])+1;
					tp-=(k*b[r]);
					ans+=k;
    			}
    			else
    			{
    				ans+=c[b[r]];
    				tp-=b[r]*c[b[r]];
    			}
    			r++;

    		}
    		for(int j=0;j<r;j++)
    		{
    			q.push(b[j]);
    		}
    			if(c[a[i]]==0)
    		{
    			q.push(a[i]);
    		}
    		c[a[i]]++;

    		printf("%d\n",ans);
    	}
    }
    return 0;

}


#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include<stack>
#include <iomanip>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define per(i,b,a) for(int i = (b) - 1; i >= (a); --i)
#define sz(a) (int)a.size()
#define de(a) cout << #a << " = " << a << endl
#define dd(a) cout << #a << " = " << a << " "
#define all(a) a.begin(), a.end()
#define pw(x) (1ll << (x))
#define mst(a,b) memset(a,b,sizeof(a));
#define lson rt<<1,l,mid
#define rson rt<<1|1,mid+1,r
typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef pair<int, int> pii;
const int inf=0x3f3f3f3f;
const int maxn=2e5+7;
int a[maxn];
int b[maxn];
int sum[maxn];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{
 	//std::ios::sync_with_stdio(false);
    //cin.tie(0);
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&a[i]);
    	sum[i]=sum[i-1]+a[i];
    }
    priority_queue<int>q;
    for(int i=1;i<=n;i++)
    {
    	if(sum[i]<=m)
    	{
    		cout<<"0"<<endl;
    		q.push(a[i]);
    	}
    	else
    	{
    		int tp=sum[i];
    		int ans=0;
    		int r=0;
    		while(!q.empty()&&tp>m)
    		{
    			b[r]=q.top();
    			q.pop();
    			tp-=b[r];
    			r++;
    			ans++;
    		}
    		for(int j=0;j<r;j++)
    		{
    			q.push(b[j]);
    		}
    		q.push(a[i]);
    		printf("%d\n",ans);
    	}
    }
    return 0;

}


#include<bits/stdc++.h>
using namespace std;

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
    else
        return false;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll temp=power(a,b/2);
    if(b%2==0)
        return temp*temp;
    else
        return temp*temp*a;
}

/*-----------------------------------------------------------------------------*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("leapfrog_ch_.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);

    ll n,m;
    cin>>n>>m;
    ll a[n],b[n],total=0,totali=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
            b[i]=a[i]+b[i-1];
        else
            b[i]=a[i];
    }
    ll ans[n];
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        if(b[i]<=m)
        {
            ans[i]=0;
            v.pb(a[i]);
        }
        else
        {
            ll p=b[i]-m;
            if(p>total)
            {
               sort(v.begin(),v.end(),greater<ll> ());
               ll sum=0;
               for(ll j=totali;j<v.size();j++)
               {
                 total+=v[j];
                 if(total>=p)
                 {
                    totali=j+1;
                    break;
                 }
               }
               ans[i]=totali;
               v.pb(a[i]);
            }
            else
            {
                ans[i]=ans[i-1];
                v.pb(a[i]);
            }
        }
    }
    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define sc(x) scanf("%lld",&x)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define cloop(i,a,b,c) for(ll i=a;i<b;i+=c)
#define cloope(i,a,b,c) for(ll i=a,i<=b;i+=c)
#define rloop(i,a,b) for(ll i=a;i>=b;i--)
#define inp(i,n,a) for(ll i=0;i<n;i++) cin>>a[i];

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
    else
        return false;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll temp=power(a,b/2);
    if(b%2==0)
        return temp*temp;
    else
        return temp*temp*a;
}

/*-----------------------------------------------------------------------------*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("leapfrog_ch_.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);

    ll n,m;
    cin>>n>>m;
    ll a[n],b[n];
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
            b[i]=a[i]+b[i-1];
        else
            b[i]=a[i];
    }
    ll ans[n],total=0,totali=0;
    multiset<ll,greater<ll> >s;
    for(ll i=0;i<n;i++)
    {
        if(b[i]<=m)
        {
            ans[i]=0;
            s.insert(a[i]);
        }
        else
        {
            ll p=b[i]-m;
           // cout<<p<<endl;
            ll sum=0,count1=0;
            multiset <ll, greater <ll> > :: iterator itr;

            for(itr=s.begin();itr!=s.end();itr++)
            {
             //   cout<<*itr<<" ";

                sum+=*itr;
                count1++;

                if(sum>=p)
                {
                    break;
                }
            }
            //cout<<endl;
            ans[i]=count1;
            s.insert(a[i]);
        }
    }
    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
    else
        return false;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll temp=power(a,b/2);
    if(b%2==0)
        return temp*temp;
    else
        return temp*temp*a;
}

/*-----------------------------------------------------------------------------*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("leapfrog_ch_.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);

    ll n,m;
    cin>>n>>m;
    ll a[n],b[n],total=0,totali=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
            b[i]=a[i]+b[i-1];
        else
            b[i]=a[i];
    }
    ll ans[n];
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        if(b[i]<=m)
        {
            ans[i]=0;
            v.pb(a[i]);
        }
        else
        {
            ll p=b[i]-m;
            if(p>total)
            {
               sort(v.begin(),v.end(),greater<ll> ());
               ll sum=0;
               for(ll j=totali;j<v.size();j++)
               {
                 total+=v[j];
                 if(total>=p)
                 {
                    totali=j+1;
                    break;
                 }
               }
               ans[i]=totali;
               v.pb(a[i]);
            }
            else
            {
                ans[i]=ans[i-1];
                v.pb(v[i]);
            }
        }
    }
    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
    else
        return false;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll temp=power(a,b/2);
    if(b%2==0)
        return temp*temp;
    else
        return temp*temp*a;
}

/*-----------------------------------------------------------------------------*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("leapfrog_ch_.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);

    ll n,m;
    cin>>n>>m;
    ll a[n],b[n],h[101]={0};
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
            b[i]=a[i]+b[i-1];
        else
            b[i]=a[i];
    }
    ll ans[n];
    for(ll i=0;i<n;i++)
    {
        ll count1=0;
        if(b[i]<=m)
        {
            ans[i]=0;
        }
        else
        {
            ll p=b[i]-m;
            for(ll j=100;j>=0;j--)
            {
                ll q=min(p,h[j]*j);
                p=p-q;
                if(q%j==0)
                    count1+=q/j;
                else
                    count1+=q/j+1;
                if(p==0)
                {
                    break;
                }
            }
            ans[i]=count1;
        }
        h[a[i]]++;
    }
    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
    else
        return false;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll temp=power(a,b/2);
    if(b%2==0)
        return temp*temp;
    else
        return temp*temp*a;
}

/*-----------------------------------------------------------------------------*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("leapfrog_ch_.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);

    ll n,m;
    cin>>n>>m;
    ll a[n],b[n],total=0,totali=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
            b[i]=a[i]+b[i-1];
        else
            b[i]=a[i];
    }
    ll ans[n];
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        if(b[i]<=m)
        {
            ans[i]=0;
            v.pb(a[i]);
        }
        else
        {
            ll p=b[i]-m;
            if(p>total)
            {
               sort(v.begin(),v.end(),greater<ll> ());
               ll sum=0;
               for(ll j=totali;j<v.size();j++)
               {
                 total+=v[j];
                 if(total>=p)
                 {
                    totali=j+1;
                    break;
                 }
               }
               ans[i]=totali;
            }
            else
            {
                ans[i]=ans[i-1];
            }
            v.pb(a[i]);
        }
    }
    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define f first
#define s second

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
    else
        return false;
}
bool isprime(ll n)
{
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            return false;
    }
    return true;
}
ll power(ll a,ll b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    ll temp=power(a,b/2);
    if(b%2==0)
        return temp*temp;
    else
        return temp*temp*a;
}

/*-----------------------------------------------------------------------------*/
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("leapfrog_ch_.txt","rt",stdin);
    //freopen("output.txt","wt",stdout);

    ll n,m;
    cin>>n>>m;
    ll a[n],b[n],total=0,totali=0;
    for(ll i=0;i<n;i++)
    {
        cin>>a[i];
        if(i>0)
            b[i]=a[i]+b[i-1];
        else
            b[i]=a[i];
    }
    ll ans[n];
    vector<ll>v;
    for(ll i=0;i<n;i++)
    {
        if(b[i]<=m)
        {
            ans[i]=0;
            v.pb(a[i]);
        }
        else
        {
            ll p=b[i]-m;
            if(p>total)
            {
               sort(v.begin(),v.end(),greater<ll> ());
               ll sum=0,count1=totali;
               for(ll j=totali;j<v.size();j++)
               {
                 total+=v[j];
                 count1++;
                 if(total>=p)
                 {
                    totali=j+1;
                    break;
                 }
               }
               ans[i]=count1;
            }
            else
            {
                ans[i]=ans[i-1];
            }
            v.pb(a[i]);
        }
    }
    for(ll i=0;i<n;i++)
        cout<<ans[i]<<" ";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,t,sum=0,cnt;
	cin>>n>>t;
	vector<int> v(n),ans(n),presum(n);
	multiset<int,greater<int>> pq;
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
		presum[i]=sum;
	}
	ans[0]=0;
	pq.insert(v[0]);
	for(int i=1;i<n;i++){
		if(presum[i]<=t){
			ans[i]=0;
			pq.insert(v[i]);
		}
		else{
			sum=0;
			cnt=0;
			vector<int> x;
			for(auto j=pq.begin();j!=pq.end();j++){
				sum+=*j;
				cnt++;
				if(presum[i]-sum<=t){
					break;
				}
			}
			pq.insert(v[i]);
			ans[i]=cnt;
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
multiset<int,greater<int>> pq;
int calc(int mid){
	int sum=0;
	for(auto i=pq.begin();mid--;i++){
		sum+=*i;
	}
	return sum;
}
int bsearch(int sum,int t ){
	int l=0,u=pq.size(),mid,ans;
	while(l<=u){
		mid=(l+u)/2;
		int val=sum-calc(mid);
		if(val>t){
			l=mid+1;
		}
		else{
			ans=mid;
			u=mid-1;
		}
	}
	return ans;
}
int main(void){
	int n,t,sum=0,cnt;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>t;
	vector<int> v(n),ans(n),presum(n);

	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
		presum[i]=sum;
	}
	ans[0]=0;
	pq.insert(v[0]);
	for(int i=1;i<n;i++){
		if(presum[i]<=t){
			ans[i]=0;
			pq.insert(v[i]);
		}
		else{
			sum=0;
			cnt=bsearch(presum[i],t);
			pq.insert(v[i]);
			ans[i]=cnt;
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


	#include<bits/stdc++.h>
	using namespace std;
	map<int,int,greater<int> > m;
	int main(void){
		int n,t,sum=0,cnt;
		ios_base::sync_with_stdio(false);
		cin.tie(NULL);
		cin>>n>>t;
		vector<int> v(n),ans(n),presum(n);

		for(int i=0;i<n;i++){
			cin>>v[i];
			sum+=v[i];
			presum[i]=sum;
		}
		ans[0]=0;
		m[v[0]]++;
		for(int i=1;i<n;i++){
			if(presum[i]<=t){
				ans[i]=0;
				m[v[i]]++;
			}
			else{
			    int cnt=0;
			    for(auto j=m.begin();j!=m.end() && presum[i]>t;j++){
			        int val=j->first,c=j->second;
			        if(presum[i]-(val*c)>=t){
			            presum[i]-=val*c;
			            cnt+=c;
			        }
			        else{
			            int l=1,u=c,mid,temp;
			            //cout<<i<<" "<<presum[i]<<" "<<u<<endl;
			            while(l<=u){
			                mid=(l+u)/2;
			                if(presum[i]-mid*val>t){
			                    l=mid+1;
			                }
			                else{
			                    temp=mid;
			                    u=mid-1;
			                }
			            }
			            cnt+=temp;
			            //cout<<cnt<<endl;
			            presum[i]-=temp*val;
			        }
			    }
			    ans[i]=cnt;
			    m[v[i]]++;
			}
		}
		for(int i=0;i<n;i++){
			cout<<ans[i]<<" ";
		}
		cout<<endl;
		return 0;
	}


#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,t,sum=0,cnt;
	cin>>n>>t;
	vector<int> v(n),ans(n),presum(n);
	priority_queue<int> pq;
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
		presum[i]=sum;
	}
	ans[0]=0;
	pq.push(v[0]);
	for(int i=1;i<n;i++){
		if(presum[i]<=t){
			ans[i]=0;
			pq.push(v[i]);
			//cout<<"size"<<pq.size()<<endl;
		}
		else{
			sum=0;
			cnt=0;
			vector<int> x;
			while(!pq.empty() && presum[i]-sum>t){
				sum+=pq.top();
				//cout<<presum[i]<<" "<<sum<<endl;
				cnt++;
				x.push_back(pq.top());
				pq.pop();
			}
			while(!x.empty()){
				pq.push(x.back());
				x.pop_back();
			}
			ans[i]=cnt;
			pq.push(v[i]);
			//cout<<"size"<<pq.size()<<endl;
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int bsearch(vector<int> presum,vector<int> v,int l,int u,int val){
	int mid,ans=0,x=u;
	while(l<=u){
		mid=(l+u)/2;

		if(presum[mid]>val){
			u=mid-1;
		}
		else{
			ans=mid;
			l=mid+1;
		}
	}
	return x-ans;
}
int main(void){
	int n,t,sum=0;
	cin>>n>>t;
	vector<int> v(n),ans(n),presum(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
		presum[i]=sum;
	}
	ans[0]=0;
	if(n>=2){
		if(presum[1]>t)
			ans[1]=1;
		else
			ans[1]=0;
	}
	for(int i=2;i<n;i++){
		if(presum[i]<=t)
			ans[i]=0;
		else
			ans[i]=bsearch(presum,v,0,i-1,t-v[i]);
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main(void){
	int n,t,sum=0,cnt;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n>>t;
	vector<int> v(n),ans(n),presum(n);
	multiset<int,greater<int>> pq;
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
		presum[i]=sum;
	}
	ans[0]=0;
	pq.insert(v[0]);
	for(int i=1;i<n;i++){
		if(presum[i]<=t){
			ans[i]=0;
			pq.insert(v[i]);
		}
		else{
			sum=0;
			cnt=0;
			vector<int> x;
			for(auto j=pq.begin();j!=pq.end();j++){
				sum+=*j;
				cnt++;
				if(presum[i]-sum<=t){
					break;
				}
			}
			pq.insert(v[i]);
			ans[i]=cnt;
		}
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int bsearch(vector<int> presum,vector<int> v,int l,int u,int val){
	int mid,ans=0,x=u;
	while(l<u){
		mid=(l+u)/2;
		if(presum[mid]>val){
			u=mid-1;
		}
		else{
			ans=mid;
			l=mid+1;
		}
	}
	return x-ans;
}
int main(void){
	int n,t,sum=0;
	cin>>n>>t;
	vector<int> v(n),ans(n),presum(n);
	for(int i=0;i<n;i++){
		cin>>v[i];
		sum+=v[i];
		presum[i]=sum;
	}
	ans[0]=0;
	if(n>=2){
		if(presum[1]>t)
			ans[1]=1;
		else
			ans[1]=0;
	}
	for(int i=2;i<n;i++){
		if(presum[i]<=t)
			ans[i]=0;
		else
			ans[i]=bsearch(presum,v,0,i-1,t-v[i]);
	}
	for(int i=0;i<n;i++){
		cout<<ans[i]<<" ";
	}
	cout<<endl;
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m,cap;
priority_queue<int,vector<int>,greater<int> > q;
int res[200010];
int space[200010];
int total=0,start=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(total+a[i]<=m){
			total+=a[i];
			res[start++] = 0;
			q.push(a[i]);
		}
	}
	for(int i=start,j;i<n;i++){
		cap = m-a[i];
		j = 0;
		while(!q.empty()&&cap>=0){
			int spa = q.top();
			//cout<<spa<<"%"<<endl;
			space[j++] = spa;
			q.pop();
			cap-=spa;
		}
		//cout<<i<<"$"<<j<<endl;
		if(cap<0)
		res[i] = (i-j+1);
		else{
			res[i] = (i-j);
		}
		for(int k = 0;k<j;k++){
			q.push(space[k]);
		}
		q.push(a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m,f=1;
priority_queue<int,vector<int>> q;
int res[200010];
int space[200010];
int total=0,start=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		//�߼�����һ����������ִ��if
		if(f&&total+a[i]<=m){
			total+=a[i];
			res[start++] = 0;
			q.push(a[i]);
		}else{
			f=0;
		}
	}

	for(int i=start,j;i<n;i++){
		j = 0;
		int tmp = total;
		while(!q.empty()&&tmp+a[i]>m){
			int spa = q.top();
			//cout<<spa<<"%"<<endl;
			space[j++] = spa;
			q.pop();
			tmp-=spa;
		}
		res[i] = j;
		//cout<<i<<"$"<<j<<endl;

		for(int k = 0;k<j;k++){
			q.push(space[k]);
		}
		q.push(a[i]);
		total+=a[i];
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m;
priority_queue<int,vector<int>,greater<int> > q;
int res[200010];
int space[200010];

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		int cap = m-a[i];
		int j = 0;
		while(!q.empty()&&cap>=0){
			int spa = q.top();
			//cout<<spa<<"%"<<endl;
			space[j++] = spa;
			q.pop();
			cap-=spa;
		}
		//cout<<i<<"$"<<j<<endl;
		if(cap<0)
		res[i] = (i-j+1);
		else{
			res[i] = (i-j);
		}
		for(int k = 0;k<j;k++){
			q.push(space[k]);
		}
		q.push(a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		if(m==6500){
			cout<<"res[316]==:"<<res[316]<<endl;
		}
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m,cap;
priority_queue<int,vector<int>,greater<int> > q;
int res[200010];
int space[200010];
int total=0,start=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		//�߼�����һ����������ִ��if
		if(total+a[i]<=m){
			total+=a[i];
			res[start++] = 0;
			q.push(a[i]);
		}else{
			total = m;
		}
	}

	for(int i=start,j;i<n;i++){
		cap = m-a[i];
		j = 0;
		while(!q.empty()&&cap>=0){
			int spa = q.top();
			//cout<<spa<<"%"<<endl;
			space[j++] = spa;
			q.pop();
			cap-=spa;
		}
		//cout<<i<<"$"<<j<<endl;
		if(cap<0)
		res[i] = (i-j+1);
		else{
			res[i] = (i-j);
		}
		for(int k = 0;k<j;k++){
			q.push(space[k]);
		}
		q.push(a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int n;
int a[200010];
map<int,int> force;

int main(){
	cin>>n;
	for(int i=1;i<=n;i++)	scanf("%d",&a[i]);
	if(n<=3){
		cout<<1;
		return 0;
	}
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++){
		force[a[i]-a[i-1]]++;
	}
	//ɾ����1����
	int key =  a[2]-a[1];
	force[key]--;
	if(force[key]==0){
		force.erase(key);
	}
	if(force.size()==1){
			cout<<1;
			return 0;
		}else{
		force[key]++;
	}
	//ɾ�����һ��Ԫ��
	 key = a[n]-a[n-1];
	 force[key]--;
	if(force[key]==0){
		force.erase(key);
	}
	if(force.size()==1){
			cout<<1;
			return n;
		}else{
		force[key]++;
	}
	 //ɾ���� 2 ~ n-1 ����
	 for(int d = 2;d < n;d++){//����ö��
	 	int key1 = a[d]-a[d-1];
	 	int key2 = a[d+1]-a[d];
	 	key = a[d+1]-a[d-1];
	 	force[key1]--;
	 	force[key2]--;
	 	force[key]++;
	 	if(force[key1]==0){
	 		force.erase(key1);
		 }
		 if(force[key2]==0){
		 	force.erase(key2);
		 }
		 if(force.size()==1){
		 	cout<<d;
		 	return 0;
		 }else{
		 	force[key1]++;
		 	force[key2]++;
			force[key]--;
			 if(force[key]==0){
	 		    force.erase(key);
		     }
		 }
	 }
	 cout<<-1;
	 return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m,cap;
priority_queue<int,vector<int>,greater<int> > q;
int res[200010];
int space[200010];
int total=0,start=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(total+a[i]<=m){
			total+=a[i];
			res[start++] = 0;
			q.push(a[i]);
		}
	}
	if(m==6500){
		cout<<"start="<<start<<" "<<res[start-1]<<" total="<<total<<endl;
	}
	for(int i=start,j;i<n;i++){
		cap = m-a[i];
		j = 0;
		while(!q.empty()&&cap>=0){
			int spa = q.top();
			//cout<<spa<<"%"<<endl;
			space[j++] = spa;
			q.pop();
			cap-=spa;
		}
		//cout<<i<<"$"<<j<<endl;
		if(cap<0)
		res[i] = (i-j+1);
		else{
			res[i] = (i-j);
		}
		for(int k = 0;k<j;k++){
			q.push(space[k]);
		}
		q.push(a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m,cap;
priority_queue<int,vector<int>,greater<int> > q;
int res[200010];
int space[200010];
int total=0,start=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(total+a[i]<=m){
			total+=a[i];
			res[start++] = 0;
			q.push(a[i]);
		}
	}
	for(int i=start,j;i<n;i++){
		cap = m-a[i];
		j = 0;
		while(!q.empty()&&cap>0){
			int spa = q.top();
			//cout<<spa<<"%"<<endl;
			space[j++] = spa;
			q.pop();
			cap-=spa;
		}
		//cout<<i<<"$"<<j<<endl;
		if(cap<0)
		res[i] = (i-j+1);
		else{
			res[i] = (i-j);
		}
		for(int k = 0;k<j;k++){
			q.push(space[k]);
		}
		q.push(a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int dp[20000010];
int res[200010];
int n,m;
int solve(int k,int cap){
	fill(dp,0);
	for(int i=0;i<k;i++){
		for(int j=cap;j>=0;j--){
			if(j>=a[i]){
				dp[j] = max(dp[j],dp[j-a[i]]+1);
			}
		}
	}
	return k-dp[cap];
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		res[i] = solve(i,m-a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m,f=1;
int q[110];
int res[200010];
int space[200010];
int total=0,start=0;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		//�߼�����һ����������ִ��if
		if(f&&total+a[i]<=m){
			total+=a[i];
			res[start++] = 0;
			q[a[i]]++;
		}else{
			f=0;
		}
	}

	for(int i=start,k,j;i<n;i++){
		int tmp = total;
		k=100;
		for(;k>=1&&tmp+a[i]>m;k--){
			tmp-=q[k]*k;
		}
		k++;
		j=0;
		while(tmp+a[i]<=m){
			tmp+=k;
			j++;
		}
		int sum=q[k]-(j-1);
		for(int l=k+1;l<=100;l++)	sum+=q[l];
		res[i] = sum;
		total+=a[i];
		q[a[i]]++;
    }

	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int dp[200010];
int res[200010];
int n,m;
int solve(int k,int cap){
	fill(dp,0);
	for(int i=0;i<k;i++){
		for(int j=cap;j>=0;j--){
			if(j>=a[i]){
				dp[j] = max(dp[j],dp[j-a[i]]+1);
			}
		}
	}
	return k-dp[cap];
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		res[i] = solve(i,m-a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


#include <bits/stdc++.h>
#define fill(x,c) memset(x,c,sizeof(x))
using namespace std;
typedef long long ll;
int a[200010];
int n,m;
priority_queue<int,vector<int>,greater<int> > q;
int res[200010];
int space[200010];

int main(){
	cin>>n>>m;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	for(int i=0;i<n;i++){
		int cap = m-a[i];
		int j = 0;
		while(!q.empty()&&cap>=0){
			int spa = q.top();
			//cout<<spa<<"%"<<endl;
			space[j++] = spa;
			q.pop();
			cap-=spa;
		}
		//cout<<i<<"$"<<j<<endl;
		if(cap<0)
		res[i] = (i-j+1);
		else{
			res[i] = (i-j);
		}
		for(int k = 0;k<j;k++){
			q.push(space[k]);
		}
		q.push(a[i]);
	}
	printf("%d",res[0]);
	for(int i=1;i<n;i++){
		printf(" %d",res[i]);
	}
	return 0;
}


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
	#define ll          long long
    #define hell        1000000007
	#define rn 			return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 2e5 + 5, K = 27;
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	vi v(n+1);
    	rep(i,1,n+1) cin>>v[i];
    	priority_queue<int> pq, rem;
    	int sum = 0, ans = 0;
    	rep(i,1,n+1){
    		sum += v[i];
    		if(sum <= m) {
    			cout<<ans<<" ";
    		}
    		else{
    			while(1){
    				int x = pq.top();
    				pq.pop();
    				sum -= x;
    				ans++;
    				rem.push(-x);
    				if(sum <= m) break;
    			}
    			cout<<ans<<" ";
    		}
    		if(!rem.empty()){
    			if(-rem.top() < v[i]){
	    			int tempsum = 0;
	    			while(1){
	    				tempsum += (-rem.top());
	    				if(tempsum > v[i]) break;
	    				int x = -rem.top();
	    				pq.push(x);
	    				sum += x;
	    				rem.pop();
	    				ans--;
	    			}
	    			rem.push(-v[i]);
	    			sum -= v[i];
	    			ans++;
    			}
    			else pq.push(v[i]);
    		}
    		else pq.push(v[i]);
    	}
    }


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
	#define ll          long long
    #define hell        1000000007
	#define rn 			return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 2e5 + 5, K = 27;
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	vi v(n+1);
    	rep(i,1,n+1) cin>>v[i];
    	priority_queue<int> pq, rem;
    	int sum = 0, ans = 0;
    	rep(i,1,n+1){
    		sum += v[i];
    		if(sum <= m) {
    			cout<<ans<<" ";
    		}
    		else{
    			while(1){
    				int v = pq.top();
    				pq.pop();
    				sum -= v;
    				ans++;
    				rem.push(-v);
    				if(sum <= m) break;
    			}
    			cout<<ans<<" ";
    		}
    		if(!rem.empty()){
    			if(-rem.top() < v[i]){
	    			int tempsum = 0;
	    			while(1){
	    				tempsum += (-rem.top());
	    				if(tempsum > v[i]) break;
	    				pq.push(-rem.top());
	    				rem.pop();
	    				ans--;
	    			}
	    			rem.push(-v[i]);
	    			ans++;
    			}
    			else pq.push(v[i]);
    		}
    		else pq.push(v[i]);
    	}
    }


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
    #define hell        1000000007
    #define rn          return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 1e3 + 5, K = 12;
    void solve(){

    }


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
	#define ll          long long
    #define hell        1000000007
	#define rn 			return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 2e5 + 5, K = 27;
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	vi v(n+1);
    	rep(i,1,n+1) cin>>v[i];
    	priority_queue<int> pq, rem;
    	int sum = 0, ans = 0;
    	rep(i,1,n+1){
    		sum += v[i];
    		if(sum <= m) {
    			cout<<ans<<" ";
    			pq.push(v[i]);
    			continue;
    		}
    		else{
    			while(1){
    				int v = pq.top();
    				pq.pop();
    				sum -= v;
    				ans++;
    				rem.push(-v);
    				if(sum <= m) break;
    			}
    			cout<<ans<<" ";
    		}
    		if(-rem.top() < v[i]){
    			int tempsum = 0;
    			while(1){
    				tempsum += (-rem.top());
    				if(tempsum > v[i]) break;
    				pq.push(-rem.top());
    				rem.pop();
    				ans--;
    			}
    			rem.push(-v[i]);
    			ans++;
    		}
    		else pq.push(v[i]);
    	}
    }


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
	#define ll          long long
    #define hell        1000000007
	#define rn 			return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 2e5 + 5, K = 27;
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	vi v(n+1);
    	rep(i,1,n+1) cin>>v[i];
    	priority_queue<int> pq;
    	int sum = 0, ans = 0;
    	rep(i,1,n+1){
    		sum += v[i];
    		if(sum <= m) cout<<ans<<" ";
    		else{
    			while(1){
    				int v = pq.top();
    				pq.pop();
    				sum -= v;
    				ans++;
    				if(sum <= m) break;
    			}
    			cout<<ans<<" ";
    		}
    		pq.push(v[i]);
    	}
    }


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
	#define ll          long long
    #define hell        1000000007
	#define rn 			return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 2e5 + 5, K = 27;
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	vi v(n+1);
    	rep(i,1,n+1) cin>>v[i];
    	priority_queue<int> pq, rem;
    	int sum = 0, ans = 0;
    	rep(i,1,n+1){
    		sum += v[i];
    		if(sum <= m) {
    			cout<<ans<<" ";
    		}
    		else{
    			while(1){
    				int x = pq.top();
    				pq.pop();
    				sum -= x;
    				ans++;
    				rem.push(-x);
    				if(sum <= m) break;
    			}
    			cout<<ans<<" ";
    		}
    		int f = 1;
    		if(!rem.empty()){
    			int temp = sum-v[i];
    			while(temp - rem.top() <= m && temp){
    				f = 0;
    				int x = -rem.top();
    				rem.pop();
    				pq.push(x);
    				temp += x;
    				ans--;
    			}
    			if(!f){
    				sum = temp;
    				rem.push(-v[i]);
    				ans++;
    			}
    			else pq.push(v[i]);
    		}
    		else pq.push(v[i]);
    	}
    }


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
	#define ll          long long
    #define hell        1000000007
	#define rn 			return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 2e5 + 5, K = 27;
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	vi v(n+1), cnt(101);
    	rep(i,1,n+1) cin>>v[i];
    	int sum = 0, ans = 0;
    	rep(i,1,n+1){
    		sum += v[i];
    		ans = 0;
    		int temp = sum - m;
	    	if(temp>0)
	    		for(int j = 100; j>0; j--){
	    			if(temp - j*cnt[j] <= 0){
	    				ans += (temp+j-1)/j;
	    				break;
	    			}
	    			ans += cnt[j];
	    			temp -= j*cnt[j];
	    		}
	    	cnt[v[i]]++;
	    	cout<<ans<<" ";
    	}

    }


    #include<bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define int         long long
    #define pb          push_back
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define all(a)      (a).begin(),(a).end()
    #define F           first
    #define S           second
	#define ll          long long
    #define hell        1000000007
	#define rn 			return
    #define INF LONG_MAX
    #define rep(i, a, b) for(int i = a; i<b; i++)
    using namespace std;
    using namespace __gnu_pbds;
    typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

    void solve();
    int absval(int x){
        if(x>=0) rn x;
        else rn -1*x;
    }
    int power(int n, int m, int mod = hell){
        if(m==0) rn 1;
        int x = power(n,m/2,mod)%mod;
        if(m%2) rn (((x*x)%mod)*n)%mod;
        else rn (x*x)%mod;
    }
    signed main()
    {
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
        int TESTS=1;
        // cin>>TESTS;
        while(TESTS--)
        {
            solve();

        }
        return 0;
    }
    const int N = 2e5 + 5, K = 27;
    void solve(){
    	int n,m;
    	cin>>n>>m;
    	vi v(n+1);
    	rep(i,1,n+1) cin>>v[i];
    	priority_queue<int> pq, rem;
    	int sum = 0, ans = 0;
    	rep(i,1,n+1){
    		sum += v[i];
    		if(sum <= m) {
    			cout<<ans<<" ";
    		}
    		else{
    			while(1){
    				int x = pq.top();
    				pq.pop();
    				sum -= x;
    				ans++;
    				rem.push(-x);
    				if(sum <= m) break;
    			}
    			cout<<ans<<" ";
    		}
    		int f = 1;
    		if(!rem.empty()){
    			int temp = sum-v[i];
    			while(temp - rem.top() <= m){
    				f = 0;
    				int x = -rem.top();
    				rem.pop();
    				pq.push(x);
    				temp += x;
    				ans--;
    			}
    			if(!f){
    				sum = temp;
    				rem.push(-v[i]);
    				ans++;
    			}
    		}
    		else pq.push(v[i]);
    	}
    }


#include<bits/stdc++.h>
using namespace std;
const int mxn = 2e5+5;
int A[mxn];
int fq[105];

int main() {
    int n,m,s=0;
    cin>>n>>m;
    int k=0,mx=0;
    for(int i=0;i<n;++i) {
        scanf("%d",&A[i]);
        s+=A[i];
        if(s<=m) {
            k++;
            printf("0 ");
            fq[A[i]]++;
            if(A[i]>mx) mx=A[i];
        }
    }
    for(int i=k;i<n;++i) {
        int sum=A[i];
        int j=0;
        int c=1;
        for(int x=1;x<=mx;++x) {
            for(int p=1;p<=fq[x];++p) {
                sum+=x;
                if(sum>m) {
                    c=0;
                    break;
                }
                j++;
            }
            if(!c) break;
        }
        //printf("#%d\n", sum-A[j]);
        printf("%d ", i-j);
        fq[A[i]]++;
        if(A[i]>mx) mx = A[i];
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mxn = 2e5+5;
int A[mxn];
int fq[105];

int main() {
    int n,m,s=0;
    cin>>n>>m;
    int k=0;
    for(int i=0;i<n;++i) {
        scanf("%d",&A[i]);
        s+=A[i];
        if(s<=m) {
            k++;
            printf("0 ");
            fq[A[i]]++;
        }
    }
    for(int i=k;i<n;++i) {
        int sum=A[i];
        int j=0;
        int c=1;
        for(int x=1;x<=100;++x) {
            for(int p=1;p<=fq[x];++p) {
                sum+=x;
                if(sum>m) {
                    c=0;
                    break;
                }
                j++;
            }
            if(!c) break;
        }
        //printf("#%d\n", sum-A[j]);
        printf("%d ", i-j);
        fq[A[i]]++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mxn = 1e3;
int A[mxn];

int main() {
    int n,m,s=0;
    cin>>n>>m;
    int k=0;
    for(int i=0;i<n;++i) {
        cin>>A[i];
        s+=A[i];
        if(s<=m) {
            k++;
            printf("0 ");
        }
    }
    for(int i=k;i<n;++i) {
        sort(A,A+i);
        int sum=A[i];
        int j;
        for(j=0;j<i;++j) {
            sum+=A[j];
            if(sum>m) {
                break;
            }
        }
        //printf("#%d\n", sum-A[j]);
        printf("%d ", i-j);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mxn = 2e5+5;
int A[mxn];

int main() {
    int n,m,s=0;
    cin>>n>>m;
    int k=0;
    for(int i=0;i<n;++i) {
        cin>>A[i];
        s+=A[i];
        if(s<=m) {
            k++;
            printf("0 ");
        }
    }
    for(int i=k;i<n;++i) {
        sort(A,A+i);
        int sum=A[i];
        int j;
        for(j=0;j<i;++j) {
            sum+=A[j];
            if(sum>m) {
                break;
            }
        }
        //printf("#%d\n", sum-A[j]);
        printf("%d ", i-j);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mxn = 2e5+5;
int A[mxn];
int fq[105];

int main() {
    int n,m,s=0;
    cin>>n>>m;
    int k=0;
    for(int i=0;i<n;++i) {
        cin>>A[i];
        s+=A[i];
        if(s<=m) {
            k++;
            printf("0 ");
            fq[A[i]]++;
        }
    }
    for(int i=k;i<n;++i) {
        int sum=A[i];
        int j=0;
        int c=1;
        for(int x=1;x<=100;++x) {
            for(int p=1;p<=fq[x];++p) {
                sum+=x;
                if(sum>m) {
                    c=0;
                    break;
                }
                j++;
            }
            if(!c) break;
        }
        //printf("#%d\n", sum-A[j]);
        printf("%d ", i-j);
        fq[A[i]]++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mxn = 2e5+5;
int A[mxn];
map<int, int> mp;

int main() {
    int n,m,s=0;
    cin>>n>>m;
    int k=0;
    for(int i=0;i<n;++i) {
        cin>>A[i];
        s+=A[i];
        if(s<=m) {
            k++;
            printf("0 ");
            mp[A[i]]++;
        }
    }
    for(int i=k;i<n;++i) {
        //sort(A,A+i);
        int sum=A[i];
        int j=0;
        int c=1;
        for(auto it=mp.begin();it!=mp.end();++it) {
        	for(int p=1;p<=it->second;++p) {
        		sum+=it->first;
        		if(sum>m) {
        			c=0;
        			break;
        		}
        		j++;
        	}
        	if(!c) break;
        }
        //printf("#%d\n", sum-A[j]);
        printf("%d ", i-j);
        mp[A[i]]++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int fq[105];

int main() {
    int a,n,m,s=0;
    scanf("%d %d",&n,&m);
    for(int i=0;i<n;++i) {
    	scanf("%d",&a);
        int sum=a, res=0;
        for(int x=1;x<=100;++x) {
            if(sum+x*fq[x] <= m) {
            	res+=fq[x];
            	sum+=x*fq[x];
            }
            else {
            	res += (m-sum)/x;
            	break;
            }
        }
        printf("%d ", i-res);
        fq[a]++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int mxn = 2e5+5;
int A[mxn];
int fq[105];

int main() {
    int n,m,s=0;
    scanf("%d %d",&n,&m);
    int k=0;
    for(int i=0;i<n;++i) {
        scanf("%d",&A[i]);
        s+=A[i];
        if(s<=m) {
            k++;
            printf("0 ");
            fq[A[i]]++;
        }
    }
    for(int i=k;i<n;++i) {
        int sum=A[i];
        int res=0;
        for(int x=1;x<=100;++x) {
            if(sum+x*fq[x] <= m) {
            	res+=fq[x];
            	sum+=x*fq[x];
            }
            else {
            	res += (m-sum)/x;
            	break;
            }
        }
        printf("%d ", i-res);
        fq[A[i]]++;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		sum=sum+a[i];int t=i-1;
		while(t>0&&a[t]<a[t-1])
		{
			int x=a[t];
			a[t]=a[t-1];
			a[t-1]=x;
		}

		if(sum<=m)
		cout<<"0 ";
		else
		{
			int p=sum;t=i-1;
			while(t>=0&&m<p)
			{
				p=p-a[t];
				t--;
			}
			cout<<(i-1-t)<<" ";
		}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		sum=sum+a[i];int t=i-1;
		while(t>0&&a[t]<a[t-1])
		{
			int x=a[t];
			a[t]=a[t-1];
			a[t-1]=x;
			t--;
		}

		if(sum<=m)
		cout<<"0 ";
		else
		{
			int p=sum;t=i-1;
			while(t>=0&&m<p)
			{
				p=p-a[t];
				t--;
			}
			cout<<(i-1-t)<<" ";
		}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		sum=sum+a[i];
		if(sum<=m)
		cout<<"0 ";
		else
		{
			int t=i-1,p=sum;
			sort(a+0,a+i);
			while(m<p&&t>=0)
			{
				p=p-a[t];
				t--;
			}
			cout<<(i-1-t)<<" ";
		}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		sum=sum+a[i];
		if(sum<=m)
		cout<<"0 ";
		else
		{
			int t=i-1,p=sum;
			if(a[i-2]>a[i-1])
			sort(a+0,a+i);
			while(m<p&&t>=0)
			{
				p=p-a[t];
				t--;
			}
			cout<<(i-1-t)<<" ";
		}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n+1],b[101]={0};
	for(i=1;i<=n;i++)
	cin>>a[i];
	for(i=1;i<=n;i++)
	{
		sum=sum+a[i];
		if(sum<=m)
		{
			cout<<"0 ";b[a[i]]++;
		}
		else
		{
		   int j=100,p=sum,k=0;
		    while(j>0)
		    {

			    p=p-j*b[j];
		   	    if(p>m)
		   	    {
		   	    	k=k+b[j];j--;
			    }
			    else if(p==m)
			    {
			    	k=k+b[j];cout<<k<<" ";b[a[i]]++;break;
				}
				else
				{
					int c=(p+j*b[j]-m);
					if(c%j==0)
					k=k+c/j;
					else
					k=k+c/j+1;
					cout<<k<<" ";b[a[i]]++;
					break;
				}
		   }
		}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,i,sum=0;
	cin>>n>>m;
	int a[n];
	for(i=0;i<n;i++)
	cin>>a[i];
	for(i=0;i<n;i++)
	{
		sum=sum+a[i];int t=i-1;
		while(a[t]<a[t-1]&&t>0)
		{
			int x=a[t];
			a[t]=a[t-1];
			a[t-1]=x;
		}

		if(sum<=m)
		cout<<"0 ";
		else
		{
			int p=sum;t=i-1;
			while(m<p&&t>=0)
			{
				p=p-a[t];
				t--;
			}
			cout<<(i-1-t)<<" ";
		}
	}
	return 0;

}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[10001];
vector<int>prime;

void seive()
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=10000;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=10000;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=10000;i++)if(!isPrime[i])prime.pb(i);
}

int main()
{
  ll n,m;
  cin>>n>>m;

  ll t[n];
  f(n)cin>>t[i];

  priority_queue<int>pq;
  priority_queue<int,vector<int>,greater<int>>pq2;

  ll sum=0,cnt=0;

  f(n)
  {
      sum+=t[i];

      while(!pq.empty() && sum>m)
      {
          sum-=pq.top();
          pq2.push(pq.top());
          pq.pop();
          cnt++;
      }

      while(!pq.empty() && !pq2.empty() && pq.top()>pq2.top())
      {
         int x=pq2.top();
         int y=pq.top();
         sum+=x;
         sum-=y;
         pq2.pop();
         pq.pop();
         pq2.push(y);
         pq.push(x);
      }
   while(!pq2.empty() && sum+pq2.top()<=m)
   {
       sum+=pq2.top();
       pq.push(pq2.top());
       pq2.pop();
       cnt--;
   }
   pq.push(t[i]);
   cout<<cnt<<' ';
  }

}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[10001];
vector<int>prime;

void seive()
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=10000;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=10000;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=10000;i++)if(!isPrime[i])prime.pb(i);
}

int main()
{
  ll n,m;
  cin>>n>>m;

  ll t[n];
  f(n)cin>>t[i];

  priority_queue<int>pq;
  priority_queue<int,vector<int>,greater<int>>pq2;
  ll sum=0,cnt=0;
  f(n)
  {
      sum+=t[i];
      while(!pq.empty() && sum>m)
      {
          cnt++;
          sum-=pq.top();
          pq2.push(pq.top());
          pq.pop();
      }

      while(!pq2.empty())
      {
          sum+=pq2.top();
          pq.push(pq2.top());
          pq2.pop();
          cnt--;
      }

      while(sum>m && !pq.empty())
      {
          sum-=pq.top();
          cnt++;
          pq2.push(pq.top());
          pq.pop();
      }
      cout<<cnt<<' ';
      pq.push(t[i]);
  }

}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[10001];
vector<int>prime;

void seive()
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=10000;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=10000;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=10000;i++)if(!isPrime[i])prime.pb(i);
}

int main()
{
  ll n,m;
  cin>>n>>m;

  ll t[n];
  f(n)cin>>t[i];

  int map[101]{0};

  ll sum=0,cnt=0;
  f(n)
  {
      sum+=t[i];
      cnt=0;
      if(sum<=m)
      {
          cout<<cnt<<' ';
          map[t[i]]++;
          continue;
      }

      int d=sum-m;

      for(int j=100;j>=1;j--)
      {
          int x=map[j]*j;
          if(d<x)
          {
              cnt+=(d+j-1)/j;
              break;
          }
         cnt+=map[j];
         d-=x;
      }
      cout<<cnt<<' ';
      map[t[i]]++;
  }

}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[10001];
vector<int>prime;

void seive()
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=10000;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=10000;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=10000;i++)if(!isPrime[i])prime.pb(i);
}

int main()
{
  ll n,m;
  cin>>n>>m;

  ll t[n];
  f(n)cin>>t[i];

  priority_queue<int>pq;
  ll sum=0,cnt=0;
  f(n)
  {
      sum+=t[i];

      while(!pq.empty() && sum>m)
      {
          cnt++;
          sum-=pq.top();
          pq.pop();
      }

      cout<<cnt<<' ';
      pq.push(t[i]);
  }

}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[10001];
vector<int>prime;

void seive()
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=10000;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=10000;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=10000;i++)if(!isPrime[i])prime.pb(i);
}

int main()
{
  ll n,m;
  cin>>n>>m;

  ll t[n];
  f(n)cin>>t[i];

  int map[101]{0};

  ll sum=0,cnt=0;
  f(n)
  {
      sum+=t[i];
      if(sum<=m)
      {
          cout<<cnt<<' ';
          map[t[i]]++;
          continue;
      }
      sum=0;cnt=0;

      for(int j=1;j<=100;j++)
      {
          if(map[j]*j+sum<=m)
          {
              sum+=(map[j]*j);
              cnt+=map[j];
          }
          else
          {
              int times=(m-sum)/j;
              cnt+=times;
              sum+=(times)*(j);
          }
      }

      cnt=i-cnt;
      cout<<cnt<<' ';
      map[t[i]]++;
  }

}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
#define ll long long int
//#define d double
#define F first
#define S second
#define FastIO ios_base::sync_with_stdio(false),cin.tie(0)
#define fix std::fixed<<setprecision(10)
const int M=1e9+7;
#define f(n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define cl(n,m) (ceil(double(n)/double(m)))
#define T() int t; cin>>t; while(t--)
#define pi pair<ll,ll>
const int MOD=1e9+7;
#define endl "\n"
const double PI = 3.141592653589793238460;
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
//bitset<N>bs;
//bitset<512>bb[512];
//vector<vector<int>>arr;

ll power(ll a,ll b)
{
    ll res=1;
    if(a==0)return 0;
    if(a==1)return 1;
    for(;b>0;b>>=1)
    {
        if(b&1)res=(res*a);
        if(res>MOD)res%=MOD;
        a=(a*a);
        if(a>MOD)a=a%MOD;
    }
    return res;
}

bool isPrime[10001];
vector<int>prime;

void seive()
{
    isPrime[0]=isPrime[1]=1;

    for(int i=2;i*i<=10000;i++)
    {
        if(!isPrime[i])
        for(int j=i*i;j<=10000;j+=i)
        {
            isPrime[j]=1;
        }
    }
    for(int i=2;i<=10000;i++)if(!isPrime[i])prime.pb(i);
}

int main()
{
  ll n,m;
  cin>>n>>m;

  ll t[n];
  f(n)cin>>t[i];

  priority_queue<int>pq;
  priority_queue<int,vector<int>,greater<int>>pq2;
  ll sum=0,cnt=0;
  f(n)
  {
      sum+=t[i];
      while(!pq.empty() && sum>m)
      {
          cnt++;
          sum-=pq.top();
          pq2.push(pq.top());
          pq.pop();
      }

      while(!pq2.empty() && !pq.empty() && pq.top()>pq2.top() && sum-pq.top()+pq2.top()<=m)
      {
          sum+=pq2.top();
          pq.push(pq2.top());
          pq2.pop();

          while(sum>m && !pq.empty())
          {
              sum-=pq.top();
              pq2.push(pq.top());
              pq.pop();
              cnt++;
          }
          cnt--;
      }
      cout<<cnt<<' ';
      pq.push(t[i]);
  }

}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    priority_queue <long long ,vector <long long> ,greater <long long> > mpq;
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,M;
    cin>>n>>M;
    vector <long long> vect(n,0),vect2;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    long long count1=0;
    priority_queue <long long> pq,pq2;
    long long sum2=0,number=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            vect2.push_back(0);
            count1+=vect[i];
            pq.push(vect[i]);
        }
        else
        {
            count1+=vect[i];
            long long sum=sum2,sum3=0,count3=0;

            if(count1<=M)
            {
                vect2.push_back(0);
                pq.push(vect[i]);
            }
            else{
                while(count1-sum2>M)
                {
                    sum2=sum2+pq.top();
                    mpq.push(pq.top());
                    pq.pop();
                    number++;
                }
                vect2.push_back(number);
                if(!mpq.empty() && vect[i]>mpq.top())
                {
                    long long count1=vect[i];
                    while(!mpq.empty() && count1>0)
                    {
                        count1-=mpq.top();
                        sum2-=mpq.top();
                        pq.push(mpq.top());
                        number--;
                    }
                    sum2+=vect[i];
                    number++;
                }
                else pq.push(vect[i]);
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,M;
    cin>>n>>M;
    vector <long long> vect(n,0),vect2;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    long long count1=0;
    priority_queue <long long> pq,pq2;
    long long sum2=0,number=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            vect2.push_back(0);
            count1+=vect[i];
            pq.push(vect[i]);
        }
        else
        {
            count1+=vect[i];
            long long sum=sum2,sum3=0,count3=0;
            priority_queue <long long ,vector <long long> ,greater <long long> > mpq;
            if(count1<=M)
            {
                vect2.push_back(0);
                pq.push(vect[i]);
            }
            else{
                while(count1-sum2>M)
                {
                    sum2=sum2+pq.top();
                    mpq.push(pq.top());
                    pq.pop();
                    number++;
                }
                vect2.push_back(number);
                if(!mpq.empty() && vect[i]>mpq.top())
                {
                    long long count1=vect[i];
                    while(!mpq.empty() && count1>0)
                    {
                        count1-=mpq.top();
                        sum2-=mpq.top();
                        pq.push(mpq.top());
                        number--;
                    }
                    sum2+=vect[i];
                    number++;
                }
                else pq.push(vect[i]);

            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,m,sum=0;
    cin>>n>>m;
    vector <long long> vect(n,0),vect2(101,0),vect3;
    for(int i=0;i<n;i++)
    {
        cin>>vect[i];
        //vect2[vect[i]]++;
    }
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            sum+=vect[0];
            vect3.push_back(0);
        }
        else
        {
            sum+=vect[i];
            long long sum2=sum,num=100,count1=0;
            vector <long long> vect4;
            vect4=vect2;
            if(sum>m)
            {
                while(sum2>m)
                {
                    if(sum2-m<=vect2[num]*num)
                    {
                        long long p=ceil((float)(sum2-m)/(float)num);
                        count1+=p;
                        break;
                    }
                    else
                    {
                        sum2-=num*vect2[num];

                        count1+=vect4[num];
                        num--;
                    }
                }
            }
            vect3.push_back(count1);

        }
        vect2[vect[i]]++;
    }
    for(int i=0;i<n;i++)
        cout<<vect3[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,M;
    cin>>n>>M;
    vector <long long> vect(n,0),vect2;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    long long count1=0;
    priority_queue <long long> pq,pq2;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            vect2.push_back(0);
            count1+=vect[i];
            pq.push(vect[i]);
        }
        else
        {
            count1+=vect[i];

            if(count1<=M)
            {
                vect2.push_back(0);
                pq.push(vect[i]);
            }
            else{
                long long sum=count1,number=0;
                //cout<<sum<<endl;
                while(sum>M)
                {
                    pq2.push(pq.top());
                    sum-=pq.top();
                    pq.pop();
                    number++;
                }
                vect2.push_back(number);
                for(int i=0;i<number;i++)
                {
                    pq.push(pq2.top());
                    pq2.pop();
                }
                pq.push(vect[i]);
            }
        }
        //cout<<count1<<endl;
    }
    for(int i=0;i<n;i++)
        cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    priority_queue <long long ,vector <long long> ,greater <long long> > mpq;
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,M;
    cin>>n>>M;
    vector <long long> vect(n,0),vect2;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    long long count1=0;
    priority_queue <long long> pq,pq2;
    long long sum2=0,number=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            vect2.push_back(0);
            count1+=vect[i];
            pq.push(vect[i]);
        }
        else
        {
            count1+=vect[i];
            long long sum=sum2,sum3=0,count3=0;

            if(count1<=M)
            {
                vect2.push_back(0);
                pq.push(vect[i]);
            }
            else{
                while(count1-sum2>M)
                {
                    sum2=sum2+pq.top();
                    mpq.push(pq.top());
                    pq.pop();
                    number++;
                }
                vect2.push_back(number);
                if(!mpq.empty() && vect[i]>mpq.top())
                {
                    long long count1=vect[i];
                    while(!mpq.empty() && count1-mpq.top()>=0)
                    {
                        count1-=mpq.top();
                        sum2-=mpq.top();
                        pq.push(mpq.top());
                        number--;
                    }
                    sum2+=vect[i];
                    number++;
                }
                else pq.push(vect[i]);
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    priority_queue <long long ,vector <long long> ,greater <long long> > mpq;
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,M;
    cin>>n>>M;
    vector <long long> vect(n,0),vect2;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    long long count1=0;
    priority_queue <long long> pq,pq2;
    long long sum2=0,number=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            vect2.push_back(0);
            count1+=vect[i];
            pq.push(vect[i]);
        }
        else
        {
            count1+=vect[i];
            long long sum=sum2,sum3=0,count3=0;

            if(count1<=M)
            {
                vect2.push_back(0);
                pq.push(vect[i]);
            }
            else{
                while(count1-sum2>M)
                {
                    sum2=sum2+pq.top();
                    mpq.push(pq.top());
                    pq.pop();
                    number++;
                }
                vect2.push_back(number);
                if(!mpq.empty() && vect[i]>mpq.top())
                {
                    long long count1=vect[i];
                    while(!mpq.empty() && count1-mpq.top()>0)
                    {
                        count1-=mpq.top();
                        sum2-=mpq.top();
                        pq.push(mpq.top());
                        number--;
                    }
                    sum2+=vect[i];
                    number++;
                }
                else pq.push(vect[i]);
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,M;
    cin>>n>>M;
    vector <long long> vect(n,0),vect2;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    long long count1=0;
    priority_queue <long long> pq,pq2;
    long long sum2=0,number=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            vect2.push_back(0);
            count1+=vect[i];
            pq.push(vect[i]);
        }
        else
        {
            count1+=vect[i];
            long long sum=sum2,sum3=0,count3=0;
            priority_queue <long long ,vector <long long> ,greater <long long> > mpq;
            if(count1<=M)
            {
                vect2.push_back(0);
                pq.push(vect[i]);
            }
            else{
                while(count1-sum2>M)
                {
                    sum2=sum2+pq.top();
                    mpq.push(pq.top());
                    pq.pop();
                    number++;
                }
                vect2.push_back(number);
                if(!mpq.empty() && vect[i]>mpq.top())
                {
                    long long count1=vect[i];
                    while(!mpq.empty() && count1-mpq.top()>0)
                    {
                        count1-=mpq.top();
                        sum2-=mpq.top();
                        pq.push(mpq.top());
                        number--;
                    }
                    sum2+=vect[i];
                    number++;
                }
                else pq.push(vect[i]);
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    long long n,M;
    cin>>n>>M;
    vector <long long> vect(n,0),vect2;
    for(int i=0;i<n;i++)
        cin>>vect[i];
    long long count1=0;
    priority_queue <long long> pq,pq2;
    long long sum2=0,number=0;
    for(int i=0;i<n;i++)
    {
        if(i==0)
        {
            vect2.push_back(0);
            count1+=vect[i];
            pq.push(vect[i]);
        }
        else
        {
            count1+=vect[i];
            long long sum=sum2,sum3=0,count3=0;
            priority_queue <long long ,vector <long long> ,greater <long long> > mpq;
            if(count1<=M)
            {
                vect2.push_back(0);
                pq.push(vect[i]);
            }
            else{
                while(count1-sum2>M)
                {
                    sum2=sum2+pq.top();
                    mpq.push(pq.top());
                    pq.pop();
                    number++;
                }
                vect2.push_back(number);
                if(!mpq.empty() && vect[i]>mpq.top())
                {
                    long long count1=vect[i];
                    while(!mpq.empty() && count1-mpq.top()>=0)
                    {
                        count1-=mpq.top();
                        sum2-=mpq.top();
                        pq.push(mpq.top());
                        number--;
                    }
                    sum2+=vect[i];
                    number++;
                }
                else pq.push(vect[i]);
            }
        }
    }
    for(int i=0;i<n;i++)
        cout<<vect2[i]<<" ";
    cout<<endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=0;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i-1]]++;
	  	int sum=0;int j=1;int ef=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];}//ef is takking them
	  	     else
	  	     break;
	  	   }
	  	   if(j==100)
	  	     out[i]=0;
	  	     else
	  	   out[i]=i-1-ef-(m-arr[i]-sum)/j+1;
	  }
	  for(int i=0;i<n;i++){
	  //if(out[i]<0)  cout<<0<<" ";
	       cout<<out[i]<<" ";}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=0;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i-1]]++;
	  	int sum=0;int j=1;int ef=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];}//ef is takking them
	  	     else
	  	     break;
	  	   }
	  	   int sum2=0;
	  	   for(int jj=1;jj<=100;jj++)
	  	   {
	  	   	sum2=sum2+jj*val[jj];
	  	   }
	  	   if(sum2<=m-arr[i])
	  	     out[i]=0;
	  	     else
	  	   out[i]=i-1-ef-(m-arr[i]-sum)/j+1;
	  }
	  for(int i=0;i<n;i++){
	  //if(out[i]<0)  cout<<0<<" ";
	       cout<<out[i]<<" ";}
	return 0;
}


{
	int n,m;cin>>n>>m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=0;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i-1]]++;
	  	int sum=0;int j=1;int ef=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];}
	  	     else
	  	     break;
	  	   }
	  	   out[i]=i-1-ef-(m-arr[i]-sum)/j+1;
	  }
	  for(int i=0;i<n;i++)
	      cout<<out[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=1;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i]]++;
	  	int sum=0;int j=1;int ef=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];}
	  	     else
	  	     break;
	  	   }
	  	   out[i]=i-1-ef+(m-arr[i]-sum)/j;
	  }
	  for(int i=0;i<n;i++)
	      cout<<out[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=0;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i-1]]++;
	  	int sum=0;int j=1;int ef=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];}//ef is takking them
	  	     else
	  	     break;
	  	   }
	  	   int sum2=0;
	  	   for(j=1;j<=100;j++)
	  	   {
	  	   	sum2=sum2+j*val[j];
	  	   }
	  	   if(sum2<=m-arr[i])
	  	     out[i]=0;
	  	     else
	  	   out[i]=i-1-ef-(m-arr[i]-sum)/j+1;
	  }
	  for(int i=0;i<n;i++){
	  //if(out[i]<0)  cout<<0<<" ";
	       cout<<out[i]<<" ";}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=0;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i-1]]++;
	  	int sum=0;int j=1;int ef=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];}
	  	     else
	  	     break;
	  	   }
	  	   out[i]=i-1-ef-(m-arr[i]-sum)/j+1;
	  }
	  for(int i=0;i<n;i++)
	      cout<<out[i]<<" ";
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=0;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i-1]]++;
	  	int sum=0;int j=1;int ef=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];}
	  	     else
	  	     break;
	  	   }
	  	   out[i]=i-1-ef-(m-arr[i]-sum)/j+1;
	  }
	  for(int i=0;i<n;i++){
	  if(out[i]<0)  cout<<0<<" ";
	      else cout<<out[i]<<" ";}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main() {
	int n,m;cin>>n>>m;
	int arr[n];int out[n];
	for(int i=0;i<n;i++)
	  {
	  	cin>>arr[i];
	  	out[i]=0;
	  }
	 int val[101];
	 for(int i=0;i<101;i++)
	  {
	  	val[i]=0;
	  }
	  //it stores answer for each n;
	  out[0]=0;
	  for(int i=1;i<n;i++)
	  {
	  	val[arr[i-1]]++;
	  	int sum=0;int j=1;int ef=0;int gg=0;
	  	for(j=1;j<=100;j++)
	  	   {
	  	     if(sum+j*val[j]<=m-arr[i])
	  	        {sum=sum+j*val[j];ef=ef+val[j];if(j==100) gg=1;}//ef is takking them
	  	     else
	  	     break;
	  	   }
	  	   if(j==100&&gg==1)
	  	     out[i]=0;
	  	     else
	  	   out[i]=i-1-ef-(m-arr[i]-sum)/j+1;
	  }
	  for(int i=0;i<n;i++){
	  //if(out[i]<0)  cout<<0<<" ";
	       cout<<out[i]<<" ";}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,cc,a[1000000],tmp,used[1000];
long long sum,s;
float nn;
int main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);

    }

    for (int i=1;i<=n;i++){
        s=sum;t=0;sum+=a[i];
        if (s+a[i]<=m) {cout<<t<<"\n";used[a[i]]++;}
        else{
        cc=a[i];;
        for (int j=100;j>=1;j--)
        if (used[j]!=0){
            if (s-used[j]*j+a[i]<=m){
                tmp=((s+a[i]-m)/j);
                nn=a[i]/j;
                if ((s+a[i]-m)%j!=0)
                t+=tmp+1;
                else
                    t+=tmp;
                break;
            }
            else{
                s=s-used[j]*j;
                t+=used[j];
                //if (s<m){
                  //  a[i]=a[i]-(m-s);
                    //s+=
                //}
                //if (a[i]<0) a[i]=0;
            }
        }
        cout<<t<<"\n";
        used[cc]++;
        }
    }
    //nn=5,99;
    //cout<<ceil(nn);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,cc,a[1000000],tmp,used[1000];
long long sum,s;
float nn;
int main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);

    }
    for (int i=1;i<=n;i++){
        s=sum;t=0;sum+=a[i];
        if (s+a[i]<=m) {cout<<t<<"\n";used[a[i]]++;}
        else{
        cc=a[i];
        for (int j=7;j>=1;j--)
        if (used[j]!=0){
            if (s-used[j]*j+a[i]<=m){
                tmp=(a[i]/j);
                nn=a[i]/j;
                if ( a[i]%j!=0)
                t+=tmp+1;
                break;
            }
            else{
                s=s-used[j]*j;
                t+=used[j];
                if (s<m)
                a[i]=a[i]-m+s;
                if (a[i]<0) a[i]=0;
            }
        }
        cout<<t<<"\n";
        used[cc]++;
        }
    }
    //nn=5,99;
    //cout<<ceil(nn);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,cc,a[1000000],tmp,used[1000];
long long sum,s;
float nn;
int main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);

    }
    for (int i=1;i<=n;i++){
        s=sum;t=0;sum+=a[i];
        if (s+a[i]<=m) {cout<<t<<"\n";used[a[i]]++;}
        else{
        cc=a[i];;
        for (int j=7;j>=1;j--)
        if (used[j]!=0){
            if (s-used[j]*j+a[i]<=m){
                tmp=(abs((s-(m-a[i])))/j);
                nn=a[i]/j;
                if ( abs((s-(m-a[i])))%j!=0)
                t+=tmp+1;
                else
                    t+=tmp;
                break;
            }
            else{
                s=s-used[j]*j;
                t+=used[j];
                if (s<m)
                a[i]=a[i]-m+s;
                if (a[i]<0) a[i]=0;
            }
        }
        cout<<t<<"\n";
        used[cc]++;
        }
    }
    //nn=5,99;
    //cout<<ceil(nn);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,cc,a[1000000],tmp,used[1000];
long long sum,s;
float nn;
int main(){
   // freopen("dd.inp","r",stdin);
   // freopen("dd.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);

    }
    for (int i=1;i<=n;i++){
        s=sum;t=0;sum+=a[i];
        if (s+a[i]<=m) {cout<<t<<"\n";used[a[i]]++;}
        else{
        cc=a[i];;
        for (int j=100;j>=1;j--)
        if (used[j]!=0){
            if (s-used[j]*j+a[i]<=m){
                tmp=((s-(m-a[i]))/j);
                nn=a[i]/j;
                if ( (s-(m-a[i]))%j!=0)
                t+=tmp+1;
                else
                    t+=tmp;
                break;
            }
            else{
                s=s-used[j]*j;
                t+=used[j];
                if (s<m)
                a[i]=a[i]-m+s;
                if (a[i]<0) a[i]=0;
            }
        }
        cout<<t<<"\n";
        used[cc]++;
        }
    }
    //nn=5,99;
    //cout<<ceil(nn);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,cc,a[1000000],tmp,used[1000];
long long sum,s;
float nn;
int main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);

    }
    for (int i=1;i<=n;i++){
        s=sum;t=0;sum+=a[i];
        if (s+a[i]<=m) {cout<<t<<"\n";used[a[i]]++;}
        else{
        cc=a[i];;
        for (int j=100;j>=1;j--)
        if (used[j]!=0){
            if (s-used[j]*j+a[i]<=m){
                tmp=(a[i]/j);
                nn=a[i]/j;
                if ( a[i]%j!=0)
                t+=tmp+1;
                else
                    t+=tmp;
                break;
            }
            else{
                s=s-used[j]*j;
                t+=used[j];
                if (s<m)
                a[i]=a[i]-m+s;
                if (a[i]<0) a[i]=0;
            }
        }
        cout<<t<<"\n";
        used[cc]++;
        }
    }
    //nn=5,99;
    //cout<<ceil(nn);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,cc,a[1000000],tmp,used[1000];
long long sum,s;
float nn;
int main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);

    }
    for (int i=1;i<=n;i++){
        s=sum;t=0;sum+=a[i];
        if (s+a[i]<=m) {cout<<t<<"\n";used[a[i]]++;}
        else{
        cc=a[i];
        for (int j=100;j>=1;j--)
        if (used[j]!=0){
            if (s-used[j]*j+a[i]<=m){
                tmp=(a[i]/j);
                nn=a[i]/j;
                if ( a[i]%j!=0)
                t+=tmp+1;
                else
                    t+=tmp;
                break;
            }
            else{
                s=s-used[j]*j;
                t+=used[j];
                if (s<m)
                a[i]=a[i]-m+s;
                if (a[i]<0) a[i]=0;
            }
        }
        cout<<t<<"\n";
        used[cc]++;
        }
    }
    //nn=5,99;
    //cout<<ceil(nn);
}


#include <bits/stdc++.h>
using namespace std;
int n,m,t,cc,a[1000000],tmp,used[1000];
long long sum,s;
float nn;
int main(){
    //freopen("dd.inp","r",stdin);
    //freopen("dd.out","w",stdout);
    scanf("%d%d",&n,&m);
    for (int i=1;i<=n;i++){
        scanf("%d",&a[i]);

    }

    for (int i=1;i<=n;i++){
        s=sum;t=0;sum+=a[i];
        if (s+a[i]<=m) {cout<<t<<"\n";used[a[i]]++;}
        else{
        cc=a[i];;
        for (int j=8;j>=1;j--)
        if (used[j]!=0){
            if (s-used[j]*j+a[i]<=m){
                tmp=((s+a[i]-m)/j);
                nn=a[i]/j;
                if ((s+a[i]-m)%j!=0)
                t+=tmp+1;
                else
                    t+=tmp;
                break;
            }
            else{
                s=s-used[j]*j;
                t+=used[j];
                //if (s<m){
                  //  a[i]=a[i]-(m-s);
                    //s+=
                //}
                //if (a[i]<0) a[i]=0;
            }
        }
        cout<<t<<"\n";
        used[cc]++;
        }
    }
    //nn=5,99;
    //cout<<ceil(nn);
}


#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007

using namespace std;
#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

bool check(ll a, ll x, ll b, ll y, ll k, ll n, vl p){
	vl v(n+1, 0), ps(n+1, 0);
	ll g = (a*b)/__gcd(a, b);
	ll j = 0;
	for (int i = g; i <= n; i+=g){
		v[i-1] = 1;
		ps[i-1] = (x+y)*(p[j]/(ll)100);
		j++;
	}
	ii ma, mi;
	if(x > y) ma = {a, x}, mi = {b, y};
	else ma = {b, y}, mi = {a, x};
	for (int i = ma.ff; i <= n; i+=ma.ff){
		if(!v[i-1]) {
			v[i-1] = 1;
			ps[i-1] = (ma.ss)*(p[j]/(ll)100);
			j++;
		}
	}
	for (int i = mi.ff; i <= n; i+=mi.ff){
		if(!v[i-1]) {
			v[i-1] = 1;
			ps[i-1] = (mi.ss)*(p[j]/(ll)100);
			j++;
		}
	}
	ll sum = (ll)0;
	for (int i = 0; i < n; ++i){
		sum+=ps[i];
 	}
	return sum-k >= 0;
}

int main(){
	ll q;
	scanf("%lld", &q);

	while(q--){
		ll n, x, a, y, b, k;
		vl p;
		scanf("%lld", &n);
		for (int i = 0; i < n; ++i){
			ll h;
			scanf("%lld", &h);
			p.pb(h);
		}
		scanf("%lld %lld %lld %lld", &x, &a, &y, &b);
		scanf("%lld", &k);
		sort(p.begin(), p.end());
		reverse(p.begin(), p.end());
		ll l = 0, r = n, ans = -1;
		while(l <= r){
			ll mid = (l+r)/2;
			if(check(a, x, b, y, k, mid, p)){
				ans = mid;
				r = mid-1;
			}else{
				l = mid+1;
			}
		}
		printf("%lld\n", ans);
	}

	return 0;
}


#include <bits/stdc++.h>

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi 3.14159265
#define oo 1000000007

using namespace std;
#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";

ll n, q;
ll p[200100], ps[200100];

bool check(ll a, ll x, ll b, ll y, ll k, ll n){
	vl v(n, 0);
	ll g = (a*b)/__gcd(a, b);
	ll j = 0;
	for (int i = g; i <= n; i+=g){
		v[i-1] = 1;
		ps[i-1] = (x+y)*(p[j]/(ll)100);
		j++;
	}
	ii ma, mi;
	if(x > y) ma = {a, x}, mi = {b, y};
	else ma = {b, y}, mi = {a, x};
	for (int i = ma.ff; i <= n; i+=ma.ff){
		if(!v[i-1]) {
			v[i-1] = 1;
			ps[i-1] = (ma.ss)*(p[j]/(ll)100);
			j++;
		}
	}
	for (int i = mi.ff; i <= n; i+=mi.ff){
		if(!v[i-1]) {
			v[i-1] = 1;
			ps[i-1] = (mi.ss)*(p[j]/(ll)100);
			j++;
		}
	}
	for (int i = 1; i <= n; i++){
		if(!v[i-1]) {
			v[i-1] = 1;
			ps[i-1] = 0;
		}
	}
	ll sum = (ll)0;
	for (int i = 0; i < n; ++i){
		sum+=ps[i];
 	}
	return (bool)(sum >= k);
}

int main(){
	scanf("%lld", &q);

	while(q--){
		ll x, a, y, b, k;
		scanf("%lld", &n);
		for (int i = 0; i < n; ++i){
			scanf("%lld", p+i);
		}
		scanf("%lld %lld %lld %lld", &x, &a, &y, &b);
		scanf("%lld", &k);
		sort(p, p+n);
		reverse(p, p+n);
		ll l = 0, r = n, ans = -1;
		while(l <= r){
			ll mid = (l+r)/2;
			if(check(a, x, b, y, k, mid)){
				ans = mid;
				r = mid-1;
			}else{
				l = mid+1;
			}
		}
		printf("%lld\n", ans);
	}

	return 0;
}