Why my answer is wrong?

#include
#include
using namespace std;
int main(){
int n,a[100000],f,e;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
cin>>e;
for(int i=0;i<e;i++){
cin>>f;
int *lb=lower_bound(a,a+n,f);
int *up=upper_bound(a,a+n,f);
if(f!=a[n-1] and (up-a)==n){
cout<<"-1"<<" “<<”-1"<<endl;
}
else{
cout<<lb-a<<" "<<up-a-1<<endl;
}
}
return 0;
}

@abheysingla2310
hello Abhey,

consider ex->
2 4 6

here lower bound and upper bound of 3 is 4 . clearly 3 is not there in the array but lower and upper bound 3 is defined.

In this problem u need to find lower and upper bound only when that element is present otherwise print -1.

to check whether element is there or not in array u can use binary search.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.