I am able to do it using loops but it is not giving the right answer when using STL. Please explain the reason.
Upper bound lower bound
You need to change two things.
First change the size of your array to 100000
Second change line 9 to cout<<it-a<<" "<<ti-a-1<<endl;