Question description In India, the real estate sector is the second-highest employment generator, after the agriculture sector. It is also expected that this sector will incur more non-resident Indian (NRI) investment, both in the short term and the long term. Bengaluru is expected to be the most favoured property investment destination for NRIs, followed by Ahmedabad, Pune, Chennai, Goa, Delhi and Dehradun. Ramesh is residing in England. he is willing to invest money in real estate. So he has chosen Bengaluru for good investment. There are N flats for sale in Bengaluru main city. The i-th flat costs Ai rupees to buy.
C Program


#include<stdio.h>

void makeheap(int x[],int n)

{

int i,j,k,t;

for(i=1;i<n;i++)

{

k=i;

while(k>0)

{

j=(k-1)/2;

if(x[j]<x[k])

{

t=x[j]; x[j]=x[k]; x[k]=t;

k=j;

}

else break;

}

}

}

void heapsort(int x[],int n)

{

int i,j,t;

makeheap(x,n);

for(i=n-1;i>0;i--)

{

t=x[0]; x[0]=x[i]; x[i]=t;

j=0;

while(2*j+1<i)

{

int l=2*j+1,r=l+1,m=l;

if(r<i && x[r]>x[l]) m=r;

if(x[j]<x[m])

{

t=x[j]; x[j]=x[m]; x[m]=t;

j=m;

}

else break;

}

}

}

int main()

{

int T;

scanf("%d",&T);

while(T--)

{

int n,b,i,count=0;

scanf("%d %d",&n,&b);

int a[n];

for(i=0;i<n;i++)

scanf("%d",&a[i]);

makeheap(a,n);

heapsort(a,n); 

for(i=0;i<n;i++)

{

if(b>=a[i])

{

b-=a[i];

count++;

}

else break;

}

printf("%d\n",count);

}

return 0;

}