#include using namespace std; const int maxn=1e5+10; int n,d,x[maxn],par[maxn]; int limit,limit1; int find_alone_inf() { int l=0,r=n+1,mid; /// l - the rightest which is smaller than d /// r - the leftest which is bigger or equal to d while(r-l>1) { mid=l+(r-l)/2; //cout<<"l=="<=d) r=mid; else l=mid; } return r; } inline int par_sum(int i,int j) { return par[j]-par[i-1]; } int find_big_num() { int l=0,r=limit,mid; /// l - the rightest num which makes sum>=d /// r - the leftest num which does not make sum>=d while(r-l>1) { mid=l+(r-l)/2; if(par_sum(mid,limit-1)>=d) l=mid; else r=mid; } return r; } int main() { /*ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);*/ fstream fin,fout; fin.open("parties.in"); fout.open("parties.out"); fin>>n>>d; //cin>>n>>d; for(int i=1;i<=n;++i) fin>>x[i]; //cin>>x[i]; sort(x+1,x+n+1); for(int i=1;i<=n;++i) { par[i]=par[i-1]+x[i]; //cout<= d /// r - the leftest num which makes the sum >= d while(r-l>1) { mid=l+(r-l)/2; if(x[mid]+sum>=d) r=mid; else l=mid; } int anscnt=(n+1-limit); if(r!=limit1) { anscnt+=(limit1-r+1); } fout<-1) { if(sum>=d) { infl=l; sum-=x[r]; --r; } else { sum+=x[l]; --l; } }*/ //fout<