View Code of Problem 133

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

Double click to view unformatted code.


Back to problem 133