View Code of Problem 133

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--&&t>=0)
 {
	int n,x;
	cin>>n>>x;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	sort(a,a+n);
	int k=0,flag=0;
	int h=n-1;
	while(k<h)
	{    
	    if(a[k]+a[h]<x) k++;
		else if(a[k]+a[h]>x) h--;
		else
		{
			flag=1;
			break;
		}
	}
	if(flag==0) cout<<"NO"<<endl;
   else 	cout<<"YES"<<endl;
 }
	return 0;
}

Double click to view unformatted code.


Back to problem 133