View Code of Problem 133

#include<stdio.h>
#include<string.h> 
#include<stdlib.h>
int cmp(const void *a,const void *b){
	return *(int*)a-*(int*)b;
}
	
int main()
{
	int t;
	scanf("%d",&t);
	while(t--)
	{
		int n,x;
		scanf("%d %d",&n,&x);
		int i,a[n];
		for(i=0;i<n;i++)
			scanf("%d",&a[i]);
		qsort(a,n,sizeof(int),cmp);
		
		for(i=0;i<n;i++)
			if(x<a[i]) break;
		int high=i;
		int low=0;
		while(low<high)
		{
			if((a[high]+a[low])==x)	
			{	
				printf("YES\n");break;
			}
			else if(a[high]+a[low]>x)
				high--;
			else if(a[high]+a[low]<x)
				low++;
		}
		if(low==high)	printf("NO\n");
	} 
	
	
	
} 

Double click to view unformatted code.


Back to problem 133