#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;
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
23 | 24 | 25 | 26 | 27 | 28 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 | 1 | 2 | 3 | 4 | 5 |
Get Free Quote!
272 Experts Online