# time limit exceed

i am not getting how to improve this:

``````
#include<stdio.h>
int main()
{
long long R,B,G,i,t,M,max1,max2,max3;
long long r[100],b[100],g[100];
scanf("%d",&t);
while(t--)
{
max1=max2=max3=0;
scanf("%d %d %d %d",&R,&G,&B,&M);
for(i=1;i<=R;i++)
{
scanf("%d",&r[i]);
if(max1<r[i])
max1=r[i];
}
for(i=1;i<=G;i++)
{
scanf("%d",&g[i]);
if(max2<g[i])
max2=g[i];
}
for(i=1;i<=B;i++)
{
scanf("%d",&b[i]);
if(max3<b[i])
max3=b[i];
}
while(M--)
{
if(max1>=max2&&max1>=max3)
max1/=2;
else if(max2>=max1&&max2>=max3)
max2/=2;
else max3/=2;
}
if(max1>=max2&&max1>=max3)
printf("%d\n",max1);
else if(max2>=max1&&max2>=max3)
printf("%d\n",max2);
else printf("%d\n",max3);
}
return 0;
}

``````

Dont get you. While taking input you write scanf M . however in the while loop you write while(m–), i.e. small m and cant see a statement where you have done m=M.

1 Like

When you post something please post the question and please intend the code!

2 Likes

Yes, the code is not properly indented. Although, I went to your profile, and grabbed your code [ I hope you don’t mind, just to help you debug it]. Everything is fine, your code doesn’t need any optimization. The only problem is you are declaring variables of long long but while taking inputs and printing them you are taking them as int(%d) and not long long int(%lld).

Here is your code with TLE: TLE
Here is your AC code by making appropriate changes %d->%lld :AC

3 Likes

Yes please indent the code properly!

1 Like

thanks kaushik, it really helped and submitted successfully.