Unable to pass all test cases

using namespace std;
#include
#include
int main()
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
cin>>a[i];

int q;		//queries
cin>>q;		
int v[q];	//array of Queries

for(int i=0;i<q;i++)
cin>>v[i];

for(int i=0;i<q;i++)
{
	auto lb=lower_bound(a,a+n,v[i])-a;
	auto ub=upper_bound(a,a+n,v[i])-a-1;
	if(lb!=n)
	{
		cout<<lb<<" "<<ub<<endl;
	}
	else
	cout<<"-1"<<" "<<"-1"<<endl;		
}

}

i have tried too many tymes but unable to pass all test cases

@n.nishchaya2000 i hope you know that the lower_bound function actually returns the index of the next smallest number just greater than that number. It does not return the first occurance of the number in the array, as is needed in the question.

lower bound return the greater than or equal to key so i got first occurance ,and upper bound return the greater than key so i subtract 1 to get the last occurance ,what’s wrong in this

sorry ma’am, i got the mistake, and thanks for telling me

@n.nishchaya2000 please mark your doubt as resolved