View Code of Problem 3686

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	int T,i,j,n,x;
	cin>>T;
	while( T-- )
	{
		cin>>n>>x;
		int a[n];
		for( i=0;i<n;i++ )
		{
			cin>>a[i];
		}
		sort(a,a+n);
		i=0;j=n-1;
		int flag =0;
		while( i<j )
		{
			if( a[i]+a[j] > x )j--;
			else if( a[i]+a[j] == x )
			{
				flag =1;
				break;
			}
			else i++;
		}
		if( flag )cout<<"YES"<<endl;
		else cout<<"NO"<<endl;
		
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 3686