View Code of Problem 133

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

Double click to view unformatted code.


Back to problem 133