View Code of Problem 133

#include<stdio.h>
#include<string.h>
#include<ctype.h> 
#include<algorithm>
using namespace std;
int main()
{
	int t,i,x,n;
	scanf("%d",&t);
	while(t--)
	{
		int flag=0,i,j,a;
		scanf("%d%d",&n,&x);
		int t[n];
		for(i=0;i<n;i++)//
		{
			scanf("%d",&t[i]);
		}
		sort(t,t+n);
		int left=0,right=n-1;//
		while(left<right)
		{
				if(t[left]+t[right]>x) right--;
				else if(t[left]+t[right]<x) left++;
				else if(t[left]+t[right]==x)
				{
					flag=1;
					break;
				}
		}
		if(flag==0) printf("NO\n");
		else printf("YES\n");
	}
	return 0;
 } 

Double click to view unformatted code.


Back to problem 133