My issue
Time Limit Exceeded
My code
# cook your dish here
x,y=map(int,input().split(" "))
a=list(map(int,input().split(" ")))
for l in range(y):
c=int(input())
z=1
for k in range(x):
z=z*(c-a[k])
if(z>0):
print("POSITIVE")
else:
print("0")
Learning course: Binary Search
Problem Link: CodeChef: Practical coding for everyone
@gunashekar22
plzz refer my c++ solution for better understanding of logic
u have to apply binary search in this problem
#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;
}