Codejam problem 3

I am getting wrong answer . My approach is to initialize two vectors with 1. Then for each time slot check if any element between them is not 1 then return -1 otherwise set all between start and end equal to 1 and return 1.

#include <bits/stdc++.h>
using namespace std;
long long int M= 1000000007;
int fun(vector& v,int start,int end)
{
for (int i = start; i < end; i++)
{ if (v[i]!=1)
{return -1;}
}
for (int i = start; i < end; i++)
{ v[i]=0; }

return 1; 

}

int main()
{ int t,z;
cin >> t;
z=t;
while (t–)
{
int n,x,k, ans,ctr=0,flag=0,ele1,ele2;
cin>>n;
string str;
vector cv(200000,1),jv(200000,1),s,e;
for (int i = 0; i < n; i++)
{ cin>>ele1>>ele2;
s.push_back(ele1);
e.push_back(ele2);
}
for ( int i = 0; i < n; i++)
{int temp=0;
temp=fun(cv,s[i],e[i]);
if(temp==1)
{str=str+‘C’;}
else if(temp==-1)
{int temp2=0;
temp2=fun(jv,s[i],e[i]);
if(temp2==1)
{str=str+‘J’;}
else if(temp2==-1)
{flag=-1;break;}
}
}
if(flag==-1)
{cout<<“Case #”<<z-t<<": IMPOSSIBLE"<<endl;}
else
{cout<<“Case #”<<z-t<<": "<<str<<endl;}

}
return 0;

}