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