Help me in solving WAV2 problem

My issue

Error: Time Limit Exceeded
How to solve this?

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	long n,q;
	cin>>n>>q;
	
	std::vector<int> a(n);
	for(int i=0;i<n;i++){
	    cin>>a[i];
	}
	
	for(int j=0;j<q;j++){
	    int x;
	    cin>>x;
	    
	    long long result = 1;
        for (int i = 0; i < n; ++i) {
            result *= (x - a[i]);
        }
        
        if(result>0){
            cout<<"POSITIVE"<<endl;
        }
        else if(result<0){
            cout<<"NEGATIVE"<<endl;
        }
        else{
            cout<<0<<endl;
        }
	}

}

Learning course: Binary Search
Problem Link: The Wave Practice Problem in Binary Search - CodeChef

@jani31
U have to apply lower bound in this
plzz refer my solution

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int n,q;
	cin>>n>>q;
	int a[n];
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	}
	sort(a,a+n);
	while(q--)
	{
	    int t;
	    cin>>t;
	    int l=lower_bound(a,a+n,t)-a;
	    if(l==n)
	    cout<<"POSITIVE";
	    else if(a[l]==t)
	    cout<<"0";
	    else 
	    {
	        int d=n-l;
	        if(d%2)
	        cout<<"NEGATIVE";
	        else
	        cout<<"POSITIVE";
	    }
	    cout<<endl;
	}
	return 0;
}