# Time Limit Exceeded : BYTEISLE problem

I am a beginner and I want to optimize my code to the problem given in title
Link to the problem is : http://www.codechef.com/problems/BYTEISLE
My code is the following in c++ :

#include
using namespace std;
int main()
{
int total,no_knights,a[50001]={0},b[50001]={0},no_byte,Case=0,slash = 0;
int ansi;
char c=‘1’,ansc[50001],temp[50001];
scanf("%d",&total);
while(Case<total)
{ //int swap = 0;
scanf("%d",&no_byte);
//if(Case==0)
for(int i=0;i<no_byte;i++)
{ slash=0;
if(i==0)
getchar_unlocked();
c=‘a’;
while(c!=’\n’)
{

``````							c=getchar_unlocked();

if(c!=' ' && slash==0)
{
a[i]=a[i]*10+(c-48);
}
else if(slash == 1 && c!=' ' && c!='\n')
{
b[i]=b[i]*10+(c-48);
}
if(c==' ')slash++;
}//while loop
}
ansi=0;
for(int no_knights=0;no_knights<=no_byte;no_knights++)
{      int count = 0,swap=0;

for(int i=0;i<no_byte;i++)
{

if(a[i]<=no_knights && b[i]>=no_knights)
{
count++;
if(ansi==0)
ansc[i]='1';
else temp[i]='1';
}
else
{
if(ansi==0)ansc[i]='0';
else temp[i]='0';
}
if(ansc[i]>temp[i] && ansi>0)swap++;
if(count>no_knights){i=no_byte;break;}
}//for loop

if(count== no_knights)
{
ansi++;
if(swap == 1)
{
int k=0;
do
{
ansc[k]=temp[k];k++;
}while(k<no_byte);
}
}
}//no knights
printf("%d\n%s",ansi,ansc);
Case++;
}
``````

return 0;
}

//