Why i am getting error in SPOJ for EKO not excepting

#include
#include
using namespace std;

bool isPossible(int a[],int mid,int N,int M)
{
int sum=0;
for(int i=0;i<N;i++)
{
if(a[i]>mid)
{
sum=sum+(a[i]-mid);
if(sum>=M)
{
return true;
}
}
}
return false;
}

int minheight(int a[],int N,int M)
{
int s=0;
int e=a[N-1];
int ans=INT_MIN;
while(s<=e)
{
int mid=(s+e)/2;
if(isPossible(a,mid,N,M))
{
ans=max(ans,mid);
s=mid+1;
}
else
{
e=mid-1;
}

}
return ans;

}

int main() {
int N,M;
cin>>N;
cin>>M;
int a[N];
for(int i=0;i<N;i++)
{
cin>>a[i];
}
cout<<minheight(a,N,M);
return 0;
}

please share ur code in cb ide

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.