View Code of Problem 133

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

Double click to view unformatted code.


Back to problem 133