spoj problem eko time limit exceeded


This is the spoj problem i am trying i am using binary search.I dont know what is wrong with this it is giving TLE on 9th test case.please help.

#include
using namespace std;
#define scanint(a) scanf("%d",&a);
int main()
{

int n,m,max=0;
scanf("%d%d",&n,&m);
int arr[n];
for(int i=0;i<n;i++)
{
scanint(arr[i]);
if(arr[i]>max)
	max=arr[i];
}
int lower=1,upper=max,temp,tempo,sum=0;
while(true)
{
	sum=0;
	temp=(lower+upper)/2;
	for(int i=0;i<n;i++)
	{
		tempo=arr[i]-temp;
		if(tempo>0)
		sum=sum+tempo;
	}
	if(sum>m)
	lower=temp;
	if(sum<m)
	upper=temp;
	if(sum==m||lower==upper||temp==1)
	{
	printf("%d\n",temp);
	break;
}


}
return 0;
}
//