#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int n,i,j,k,low,up,mid;
cout<<"Enter the number of elements(any positive integer)"<<endl;
cin>>n;
int a[n];
cout<<"Enter the elements one by one"<<endl;
for(i=0;i<n;i++)
cin>>a[i];
for(i=1;i<n;i++)
{
k=a[i];
for(j=i-1;j>=0 && k<a[j];j--)
a[j+1]=a[j];
a[j+1]=k;
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
k=(a[i]+a[j])*(-1);
low=0;
up=n-1;
while(low<=up)
{
mid=(low+up)/2;
if(k>a[mid])
low=mid+1;
else if(k<a[mid])
up=mid-1;
else
{
cout<<"YES";
exit(1);
}
}
}
}
cout<<"NO";
return 0;
Get Free Quote!
416 Experts Online